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 <hintids.hxx>
26 #include <editeng/wghtitem.hxx>
27 #include <editeng/adjitem.hxx>
28 #ifndef __RSC //autogen
29 #include <tools/errinf.hxx>
30 #endif
31 #ifndef _MSGBOX_HXX //autogen
32 #include <vcl/msgbox.hxx>
33 #endif
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
36 #endif
37 #include <svl/macitem.hxx>
38 #include <sfx2/fcontnr.hxx>
39 #include <sfx2/docfile.hxx>
40 #define _SVSTDARR_STRINGS
41 #include <svl/svstdarr.hxx>
42 #include <svl/urihelper.hxx>
43 #include <unotools/transliterationwrapper.hxx>
44 #include <poolfmt.hxx>
45 #include <fmtcol.hxx>
46 #include <docary.hxx>
47 #include <wrtsh.hxx>
48 #include <uitool.hxx> // Fehlermeldungen
49 #include <view.hxx>
50 #include <swevent.hxx>
51 #include <gloshdl.hxx>
52 #include <glosdoc.hxx>
53 #include <shellio.hxx>
54 #include <swundo.hxx> // fuer Undo-Ids
55 #include <expfld.hxx>
56 #include <initui.hxx> // fuer ::GetGlossaries()
57 #include <gloslst.hxx>
58 #include <swdtflvr.hxx>
59 #ifndef _DOCSH_HXX
60 #include <docsh.hxx>
61 #endif
62 #include <crsskip.hxx>
63
64 #ifndef _DOCHDL_HRC
65 #include <dochdl.hrc>
66 #endif
67 #ifndef _SWERROR_H
68 #include <swerror.h>
69 #endif
70 #include <frmmgr.hxx>
71 #ifndef _LSTBOX_HXX //autogen
72 #include <vcl/lstbox.hxx>
73 #endif
74
75 #include <editeng/acorrcfg.hxx>
76 #include "swabstdlg.hxx"
77 #include <misc.hrc>
78
79 #include <IDocumentFieldsAccess.hxx>
80
81 using namespace ::com::sun::star;
82
83 const short RET_EDIT = 100;
84
85 // PUBLIC METHODES -------------------------------------------------------
86 struct TextBlockInfo_Impl
87 {
88 String sTitle;
89 String sLongName;
90 String sGroupName;
91 };
92 typedef TextBlockInfo_Impl* TextBlockInfo_ImplPtr;
93 SV_DECL_PTRARR_DEL( TextBlockInfoArr, TextBlockInfo_ImplPtr, 0, 4 )
SV_IMPL_PTRARR(TextBlockInfoArr,TextBlockInfo_ImplPtr)94 SV_IMPL_PTRARR( TextBlockInfoArr, TextBlockInfo_ImplPtr )
95 SV_IMPL_REF( SwDocShell )
96 /*------------------------------------------------------------------------
97 Beschreibung: Dialog fuer Bearbeiten Vorlagen
98 ------------------------------------------------------------------------*/
99
100
101 void SwGlossaryHdl::GlossaryDlg()
102 {
103 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
104 DBG_ASSERT(pFact, "Dialogdiet fail!");
105 AbstractGlossaryDlg* pDlg = pFact->CreateGlossaryDlg( DLG_RENAME_GLOS,
106 pViewFrame, this, pWrtShell);
107 DBG_ASSERT(pDlg, "Dialogdiet fail!");
108 String sName, sShortName;
109
110 if( RET_EDIT == pDlg->Execute() )
111 {
112 sName = pDlg->GetCurrGrpName();
113 sShortName = pDlg->GetCurrShortName();
114 }
115
116 delete pDlg;
117 DELETEZ(pCurGrp);
118 if(HasGlossaryList())
119 {
120 GetGlossaryList()->ClearGroups();
121 }
122
123 if( sName.Len() || sShortName.Len() )
124 rStatGlossaries.EditGroupDoc( sName, sShortName );
125 }
126
127 /*------------------------------------------------------------------------
128 Beschreibung: Setzen der aktuellen Gruppe; falls aus dem Dialog
129 gerufen, wird die Gruppe temp. erzeugt fuer einen
130 schnelleren Zugriff
131 ------------------------------------------------------------------------*/
132
133
SetCurGroup(const String & rGrp,sal_Bool bApi,sal_Bool bAlwaysCreateNew)134 void SwGlossaryHdl::SetCurGroup(const String &rGrp, sal_Bool bApi, sal_Bool bAlwaysCreateNew )
135 {
136 String sGroup(rGrp);
137 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM) && !FindGroupName(sGroup))
138 {
139 sGroup += GLOS_DELIM;
140 sGroup += '0';
141 }
142 if(pCurGrp)
143 {
144 sal_Bool bPathEqual = sal_False;
145 if(!bAlwaysCreateNew)
146 {
147 INetURLObject aTemp( pCurGrp->GetFileName() );
148 String sCurBase = aTemp.getBase();
149 aTemp.removeSegment();
150 const String sCurEntryPath = aTemp.GetMainURL(INetURLObject::NO_DECODE);
151 const SvStrings* pPathArr = rStatGlossaries.GetPathArray();
152 sal_uInt16 nCurrentPath = USHRT_MAX;
153 for(sal_uInt16 nPath = 0; nPath < pPathArr->Count(); nPath++)
154 {
155 if(sCurEntryPath == *(*pPathArr)[nPath])
156 {
157 nCurrentPath = nPath;
158 break;
159 }
160 }
161 String sPath = sGroup.GetToken(1, GLOS_DELIM);
162 sal_uInt16 nComparePath = (sal_uInt16)sPath.ToInt32();
163 if(nCurrentPath == nComparePath &&
164 sGroup.GetToken(0, GLOS_DELIM) == sCurBase)
165 bPathEqual = sal_True;
166 }
167 // const String aMac_Tmp(pCurGrp->GetName());
168 // Beim Pfadwechsel kann man sich auf den Namen nicht verlassen
169 if(!bAlwaysCreateNew &&
170 bPathEqual
171 // aMac_Tmp == sGroup
172 )
173 return;
174 }
175 aCurGrp = sGroup;
176 if(!bApi)
177 {
178 if(pCurGrp)
179 {
180 rStatGlossaries.PutGroupDoc(pCurGrp);
181 pCurGrp = 0;
182 }
183 pCurGrp = rStatGlossaries.GetGroupDoc(aCurGrp, sal_True);
184 }
185 }
186
187 /*------------------------------------------------------------------------
188 Beschreibung:
189 ------------------------------------------------------------------------*/
190
191
GetGroupCnt() const192 sal_uInt16 SwGlossaryHdl::GetGroupCnt() const
193 {
194 return rStatGlossaries.GetGroupCnt();
195 }
196
197 /*------------------------------------------------------------------------
198 Beschreibung:
199 ------------------------------------------------------------------------*/
200
201
GetGroupName(sal_uInt16 nId,String * pTitle)202 String SwGlossaryHdl::GetGroupName( sal_uInt16 nId, String* pTitle )
203 {
204 String sRet = rStatGlossaries.GetGroupName(nId);
205 if(pTitle)
206 {
207 SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sRet, sal_False);
208 if(pGroup && !pGroup->GetError())
209 {
210 *pTitle = pGroup->GetName();
211 if(!pTitle->Len())
212 {
213 *pTitle = sRet.GetToken(0, GLOS_DELIM);
214 pGroup->SetName(*pTitle);
215 }
216 rStatGlossaries.PutGroupDoc( pGroup );
217 }
218 else
219 sRet.Erase();
220 }
221 return sRet;
222 }
223 /*------------------------------------------------------------------------
224 Beschreibung:
225 ------------------------------------------------------------------------*/
226
227
NewGroup(String & rGrpName,const String & rTitle)228 sal_Bool SwGlossaryHdl::NewGroup(String &rGrpName, const String& rTitle)
229 {
230 if(STRING_NOTFOUND == rGrpName.Search(GLOS_DELIM))
231 FindGroupName(rGrpName);
232 return rStatGlossaries.NewGroupDoc(rGrpName, rTitle);
233 }
234 /* -----------------23.11.98 13:10-------------------
235 * Umbenennen eines Textbausteins
236 * --------------------------------------------------*/
RenameGroup(const String & rOld,String & rNew,const String & rNewTitle)237 sal_Bool SwGlossaryHdl::RenameGroup(const String & rOld, String& rNew, const String& rNewTitle)
238 {
239 sal_Bool bRet = sal_False;
240 String sOldGroup(rOld);
241 if(STRING_NOTFOUND == rOld.Search(GLOS_DELIM))
242 FindGroupName(sOldGroup);
243 if(rOld == rNew)
244 {
245 SwTextBlocks* pGroup = rStatGlossaries.GetGroupDoc(sOldGroup, sal_False);
246 if(pGroup)
247 {
248 pGroup->SetName(rNewTitle);
249 rStatGlossaries.PutGroupDoc( pGroup );
250 bRet = sal_True;
251 }
252 }
253 else
254 {
255 String sNewGroup(rNew);
256 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM))
257 {
258 sNewGroup += GLOS_DELIM;
259 sNewGroup += '0';
260 }
261 bRet = rStatGlossaries.RenameGroupDoc(sOldGroup, sNewGroup, rNewTitle);
262 rNew = sNewGroup;
263 }
264 return bRet;
265 }
266 /* -----------------27.11.98 13:49-------------------
267 *
268 * --------------------------------------------------*/
CopyOrMove(const String & rSourceGroupName,String & rSourceShortName,const String & rDestGroupName,const String & rLongName,sal_Bool bMove)269 sal_Bool SwGlossaryHdl::CopyOrMove( const String& rSourceGroupName, String& rSourceShortName,
270 const String& rDestGroupName, const String& rLongName, sal_Bool bMove )
271 {
272 SwTextBlocks* pSourceGroup = rStatGlossaries.GetGroupDoc(rSourceGroupName, sal_False);
273
274 SwTextBlocks* pDestGroup = rStatGlossaries.GetGroupDoc(rDestGroupName, sal_False);
275 if(pDestGroup->IsReadOnly() || (bMove && pSourceGroup->IsReadOnly()) )
276 return sal_False;
277 /*if(pDestGroup->IsOld()&& 0!= pDestGroup->ConvertToNew())
278 return sal_False;
279 if(bMove && pSourceGroup->IsOld() && 0 != pSourceGroup->ConvertToNew())
280 return sal_False;*/
281
282 //Der Index muss hier ermittelt werden, weil rSourceShortName in CopyBlock evtl veraendert wird
283 sal_uInt16 nDeleteIdx = pSourceGroup->GetIndex( rSourceShortName );
284 DBG_ASSERT(USHRT_MAX != nDeleteIdx, "Eintrag nicht gefunden");
285 sal_uLong nRet = pSourceGroup->CopyBlock( *pDestGroup, rSourceShortName, rLongName );
286 if(!nRet && bMove)
287 {
288 // der Index muss existieren
289 nRet = pSourceGroup->Delete( nDeleteIdx ) ? 0 : 1;
290 }
291 rStatGlossaries.PutGroupDoc( pSourceGroup );
292 rStatGlossaries.PutGroupDoc( pDestGroup );
293 return !nRet;
294 }
295
296 /*------------------------------------------------------------------------
297 Beschreibung: Loeschen einer Textbausteindatei-Gruppe
298 ------------------------------------------------------------------------*/
299
300
DelGroup(const String & rGrpName)301 sal_Bool SwGlossaryHdl::DelGroup(const String &rGrpName)
302 {
303 String sGroup(rGrpName);
304 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM))
305 FindGroupName(sGroup);
306 if( rStatGlossaries.DelGroupDoc(sGroup) )
307 {
308 if(pCurGrp)
309 {
310 const String aMac_Tmp(pCurGrp->GetName());
311 if(aMac_Tmp == sGroup)
312 DELETEZ(pCurGrp);
313 }
314 return sal_True;
315 }
316 return sal_False;
317 }
318
319 /*------------------------------------------------------------------------
320 Beschreibung: Anzahl Textbausteine erfragen
321 ------------------------------------------------------------------------*/
322
323
GetGlossaryCnt()324 sal_uInt16 SwGlossaryHdl::GetGlossaryCnt()
325 {
326 return pCurGrp ? pCurGrp->GetCount() : 0;
327 }
328
329 /*------------------------------------------------------------------------
330 Beschreibung:
331 ------------------------------------------------------------------------*/
332
333
GetGlossaryName(sal_uInt16 nId)334 String SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId )
335 {
336 ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.);
337 return pCurGrp->GetLongName( nId );
338 }
339 /* -----------------30.11.98 13:18-------------------
340 *
341 * --------------------------------------------------*/
GetGlossaryShortName(sal_uInt16 nId)342 String SwGlossaryHdl::GetGlossaryShortName(sal_uInt16 nId)
343 {
344 ASSERT(nId < GetGlossaryCnt(), Textbausteinarray ueberindiziert.);
345 return pCurGrp->GetShortName( nId );
346 }
347
348
349 /*------------------------------------------------------------------------
350 Beschreibung: Kurzname erfragen
351 ------------------------------------------------------------------------*/
352
353
GetGlossaryShortName(const String & rName)354 String SwGlossaryHdl::GetGlossaryShortName(const String &rName)
355 {
356 String sReturn;
357 SwTextBlocks *pTmp =
358 pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, sal_False );
359 if(pTmp)
360 {
361 sal_uInt16 nIdx = pTmp->GetLongIndex( rName );
362 if( nIdx != (sal_uInt16) -1 )
363 sReturn = pTmp->GetShortName( nIdx );
364 if( !pCurGrp )
365 rStatGlossaries.PutGroupDoc( pTmp );
366 }
367 return sReturn;
368 }
369
370 /*------------------------------------------------------------------------
371 Beschreibung: Kuerzel fuer Textbaustein bereits verwendet?
372 ------------------------------------------------------------------------*/
373
374
HasShortName(const String & rShortName) const375 sal_Bool SwGlossaryHdl::HasShortName(const String& rShortName) const
376 {
377 SwTextBlocks *pBlock = pCurGrp ? pCurGrp
378 : rStatGlossaries.GetGroupDoc( aCurGrp );
379 sal_Bool bRet = pBlock->GetIndex( rShortName ) != (sal_uInt16) -1;
380 if( !pCurGrp )
381 rStatGlossaries.PutGroupDoc( pBlock );
382 return bRet;
383 }
384
385 /* -----------------------------20.03.01 10:52--------------------------------
386
387 ---------------------------------------------------------------------------*/
ConvertToNew(SwTextBlocks &)388 sal_Bool SwGlossaryHdl::ConvertToNew(SwTextBlocks& /*rOld*/)
389 {
390 /*if( rOld.IsOld() )
391 {
392 QueryBox aAsk( pWrtShell->GetView().GetWindow(), SW_RES( MSG_UPDATE_NEW_GLOS_FMT ) );
393 if( aAsk.Execute() == RET_YES )
394 {
395 if( rOld.ConvertToNew() )
396 {
397 InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute();
398 return sal_False;
399 }
400 }
401 else
402 return sal_False;
403 }*/
404 return sal_True;
405 }
406
407 /*------------------------------------------------------------------------
408 Beschreibung: Erzeugen eines Textbausteines
409 ------------------------------------------------------------------------*/
410
NewGlossary(const String & rName,const String & rShortName,sal_Bool bCreateGroup,sal_Bool bNoAttr)411 sal_Bool SwGlossaryHdl::NewGlossary(const String& rName, const String& rShortName,
412 sal_Bool bCreateGroup, sal_Bool bNoAttr)
413 {
414 SwTextBlocks *pTmp =
415 pCurGrp ? pCurGrp: rStatGlossaries.GetGroupDoc( aCurGrp, bCreateGroup );
416 //pTmp == 0 if the AutoText path setting is wrong
417 if(!pTmp)
418 return sal_False;
419 if(!ConvertToNew(*pTmp))
420 return sal_False;
421
422 String sOnlyTxt;
423 String* pOnlyTxt = 0;
424 if( bNoAttr )
425 {
426 if( !pWrtShell->GetSelectedText( sOnlyTxt, GETSELTXT_PARABRK_TO_ONLYCR ))
427 return sal_False;
428 pOnlyTxt = &sOnlyTxt;
429 }
430
431 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
432
433 const sal_uInt16 nSuccess = pWrtShell->MakeGlossary( *pTmp, rName, rShortName,
434 pCfg->IsSaveRelFile(), pOnlyTxt );
435 if(nSuccess == (sal_uInt16) -1 )
436 {
437 InfoBox(pWrtShell->GetView().GetWindow(), SW_RES(MSG_ERR_INSERT_GLOS)).Execute();
438 }
439 if( !pCurGrp )
440 rStatGlossaries.PutGroupDoc( pTmp );
441 return sal_Bool( nSuccess != (sal_uInt16) -1 );
442 }
443 /*------------------------------------------------------------------------
444 Beschreibung: Loeschen eines Textbausteines
445 ------------------------------------------------------------------------*/
446
447
DelGlossary(const String & rShortName)448 sal_Bool SwGlossaryHdl::DelGlossary(const String &rShortName)
449 {
450 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
451 : rStatGlossaries.GetGroupDoc(aCurGrp);
452 //pTmp == 0 if the AutoText path setting is wrong
453 if(!pGlossary || !ConvertToNew(*pGlossary))
454 return sal_False;
455
456 sal_uInt16 nIdx = pGlossary->GetIndex( rShortName );
457 if( nIdx != (sal_uInt16) -1 )
458 pGlossary->Delete( nIdx );
459 if( !pCurGrp )
460 rStatGlossaries.PutGroupDoc( pGlossary );
461 return sal_True;
462 }
463
464 /*------------------------------------------------------------------------
465 Beschreibung: Kurzform expandieren
466 ------------------------------------------------------------------------*/
467
468
ExpandGlossary()469 sal_Bool SwGlossaryHdl::ExpandGlossary()
470 {
471 ASSERT(pWrtShell->CanInsert(), illegal);
472 SwTextBlocks *pGlossary;
473 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
474 DBG_ASSERT(pFact, "Dialogdiet fail!");
475 ::GlossaryGetCurrGroup fnGetCurrGroup = pFact->GetGlossaryCurrGroupFunc( DLG_RENAME_GLOS );
476 DBG_ASSERT(fnGetCurrGroup, "Dialogdiet fail!");
477 String sGroupName( (*fnGetCurrGroup)() );
478 if(STRING_NOTFOUND == sGroupName.Search(GLOS_DELIM))
479 FindGroupName(sGroupName);
480 pGlossary = rStatGlossaries.GetGroupDoc(sGroupName);
481
482 String aShortName;
483
484 // bei Textselektion diese verwenden
485 if(pWrtShell->SwCrsrShell::HasSelection() && !pWrtShell->IsBlockMode())
486 {
487 aShortName = pWrtShell->GetSelTxt();
488 }
489 else
490 {
491 if(pWrtShell->IsAddMode())
492 pWrtShell->LeaveAddMode();
493 else if(pWrtShell->IsBlockMode())
494 pWrtShell->LeaveBlockMode();
495 else if(pWrtShell->IsExtMode())
496 pWrtShell->LeaveExtMode();
497 // Wort selektieren
498 pWrtShell->SelNearestWrd();
499 // Wort erfragen
500 if(pWrtShell->IsSelection())
501 aShortName = pWrtShell->GetSelTxt();
502 }
503 return pGlossary ? Expand( aShortName, &rStatGlossaries, pGlossary ) : sal_False;
504 }
505
Expand(const String & rShortName,SwGlossaries * pGlossaries,SwTextBlocks * pGlossary)506 sal_Bool SwGlossaryHdl::Expand( const String& rShortName,
507 SwGlossaries *pGlossaries,
508 SwTextBlocks *pGlossary )
509 {
510 TextBlockInfoArr aFoundArr;
511 String aShortName( rShortName );
512 sal_Bool bCancel = sal_False;
513 // search for text block
514 //#b6633427# - don't prefer current group depending on configuration setting
515 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
516 sal_uInt16 nFound = !pCfg->IsSearchInAllCategories() ? pGlossary->GetIndex( aShortName ) : -1;
517 // if not found then search in all groups
518 if( nFound == (sal_uInt16) -1 )
519 {
520 const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
521 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
522 sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount();
523 for(sal_uInt16 i = 1; i <= nGroupCount; i++)
524 {
525 // Gruppenname mit Pfad-Extension besorgen
526 String sTitle;
527 String sGroupName = pGlossaryList->GetGroupName(i - 1, sal_False, &sTitle);
528 if(sGroupName == pGlossary->GetName())
529 continue;
530 sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
531 if(nBlockCount)
532 {
533 for(sal_uInt16 j = 0; j < nBlockCount; j++)
534 {
535 String sEntry;
536 String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry));
537 if( rSCmp.isEqual( rShortName, sEntry ))
538 {
539 TextBlockInfo_Impl* pData = new TextBlockInfo_Impl;
540 pData->sTitle = sTitle;
541 pData->sLongName = sLongName;
542 pData->sGroupName = sGroupName;
543 aFoundArr.Insert(pData, aFoundArr.Count());
544 }
545 }
546 }
547 }
548 if( aFoundArr.Count() ) // einer wurde gefunden
549 {
550 pGlossaries->PutGroupDoc(pGlossary);
551 if(1 == aFoundArr.Count())
552 {
553 TextBlockInfo_Impl* pData = aFoundArr.GetObject(0);
554 pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName);
555 nFound = pGlossary->GetIndex( aShortName );
556 }
557 else
558 {
559 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
560 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
561
562 AbstractSwSelGlossaryDlg* pDlg = pFact->CreateSwSelGlossaryDlg( 0, aShortName, DLG_SEL_GLOS );
563 DBG_ASSERT(pDlg, "Dialogdiet fail!");
564 for(sal_uInt16 i = 0; i < aFoundArr.Count(); ++i)
565 {
566 TextBlockInfo_Impl* pData = aFoundArr.GetObject(i);
567 pDlg->InsertGlos(pData->sTitle, pData->sLongName);
568 }
569 pDlg->SelectEntryPos(0);
570 const sal_uInt16 nRet = RET_OK == pDlg->Execute()?
571 pDlg->GetSelectedIdx():
572 LISTBOX_ENTRY_NOTFOUND;
573 delete pDlg;
574 if(LISTBOX_ENTRY_NOTFOUND != nRet)
575 {
576 TextBlockInfo_Impl* pData = aFoundArr.GetObject(nRet);
577 pGlossary = (SwTextBlocks *)pGlossaries->GetGroupDoc(pData->sGroupName);
578 nFound = pGlossary->GetIndex( aShortName );
579 }
580 else
581 {
582 nFound = (sal_uInt16) -1;
583 bCancel = sal_True;
584 }
585 }
586 }
587 }
588
589 // not found
590 if( nFound == (sal_uInt16) -1 )
591 {
592 if( !bCancel )
593 {
594 pGlossaries->PutGroupDoc(pGlossary);
595
596 const sal_uInt16 nMaxLen = 50;
597 if(pWrtShell->IsSelection() && aShortName.Len() > nMaxLen)
598 {
599 aShortName.Erase(nMaxLen);
600 aShortName.AppendAscii(" ...");
601 }
602 String aTmp( SW_RES(STR_NOGLOS));
603 aTmp.SearchAndReplaceAscii("%1", aShortName);
604 InfoBox( pWrtShell->GetView().GetWindow(), aTmp ).Execute();
605 }
606
607 return sal_False;
608 }
609 else
610 {
611 String aLongName = pGlossary->GetLongName( nFound );
612 SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC);
613 SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC);
614 GetMacros( aShortName, aStartMacro, aEndMacro, pGlossary );
615
616 // StartAction darf nicht vor HasSelection und DelRight stehen,
617 // sonst wird der mögliche Shellwechsel verzögert und
618 // API-Programme würden dann hängenbleiben
619 // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden
620 pWrtShell->StartUndo(UNDO_INSGLOSSARY);
621 if( aStartMacro.GetMacName().Len() )
622 pWrtShell->ExecMacro( aStartMacro );
623 if(pWrtShell->HasSelection())
624 pWrtShell->DelLeft();
625 pWrtShell->StartAllAction();
626
627 // alle InputFelder zwischenspeichern
628 SwInputFieldList aFldLst( pWrtShell, sal_True );
629
630 pWrtShell->InsertGlossary(*pGlossary, aShortName);
631 pWrtShell->EndAllAction();
632 if( aEndMacro.GetMacName().Len() )
633 {
634 pWrtShell->ExecMacro( aEndMacro );
635 }
636 pWrtShell->EndUndo(UNDO_INSGLOSSARY);
637
638 // für alle neuen InputFelder die Eingaben abfordern
639 if( aFldLst.BuildSortLst() )
640 pWrtShell->UpdateInputFlds( &aFldLst );
641 }
642 pGlossaries->PutGroupDoc(pGlossary);
643 return sal_True;
644 }
645
646 /*------------------------------------------------------------------------
647 Beschreibung: Textbaustein einfuegen
648 ------------------------------------------------------------------------*/
649
650
InsertGlossary(const String & rName)651 sal_Bool SwGlossaryHdl::InsertGlossary(const String &rName)
652 {
653 ASSERT(pWrtShell->CanInsert(), illegal);
654
655 SwTextBlocks *pGlos =
656 pCurGrp? pCurGrp: rStatGlossaries.GetGroupDoc(aCurGrp);
657
658 if (!pGlos)
659 return sal_False;
660
661 SvxMacro aStartMacro(aEmptyStr, aEmptyStr, STARBASIC);
662 SvxMacro aEndMacro(aEmptyStr, aEmptyStr, STARBASIC);
663 GetMacros( rName, aStartMacro, aEndMacro, pGlos );
664
665 // StartAction darf nicht vor HasSelection und DelRight stehen,
666 // sonst wird der mögliche Shellwechsel verzögert und
667 // API-Programme würden dann hängenbleiben
668 // ausserdem darf das Ereignismacro ebenfalls nicht in einer Action gerufen werden
669 if( aStartMacro.GetMacName().Len() )
670 pWrtShell->ExecMacro( aStartMacro );
671 if( pWrtShell->HasSelection() )
672 pWrtShell->DelRight();
673 pWrtShell->StartAllAction();
674
675 // alle InputFelder zwischenspeichern
676 SwInputFieldList aFldLst( pWrtShell, sal_True );
677
678 pWrtShell->InsertGlossary(*pGlos, rName);
679 pWrtShell->EndAllAction();
680 if( aEndMacro.GetMacName().Len() )
681 {
682 pWrtShell->ExecMacro( aEndMacro );
683 }
684
685 // fuer alle neuen InputFelder die Eingaben abfordern
686 if( aFldLst.BuildSortLst() )
687 pWrtShell->UpdateInputFlds( &aFldLst );
688
689 if(!pCurGrp)
690 rStatGlossaries.PutGroupDoc(pGlos);
691 return sal_True;
692 }
693
694 /*------------------------------------------------------------------------
695 Beschreibung: Macro setzen / erfragen
696 ------------------------------------------------------------------------*/
697
698
SetMacros(const String & rShortName,const SvxMacro * pStart,const SvxMacro * pEnd,SwTextBlocks * pGlossary)699 void SwGlossaryHdl::SetMacros(const String& rShortName,
700 const SvxMacro* pStart,
701 const SvxMacro* pEnd,
702 SwTextBlocks *pGlossary )
703 {
704 SwTextBlocks *pGlos = pGlossary ? pGlossary :
705 pCurGrp ? pCurGrp
706 : rStatGlossaries.GetGroupDoc( aCurGrp );
707 SvxMacroTableDtor aMacroTbl;
708 if( pStart )
709 aMacroTbl.Insert( SW_EVENT_START_INS_GLOSSARY, new SvxMacro(*pStart));
710 if( pEnd )
711 aMacroTbl.Insert( SW_EVENT_END_INS_GLOSSARY, new SvxMacro(*pEnd));
712 sal_uInt16 nIdx = pGlos->GetIndex( rShortName );
713 if( !pGlos->SetMacroTable( nIdx, aMacroTbl ) && pGlos->GetError() )
714 ErrorHandler::HandleError( pGlos->GetError() );
715
716 if(!pCurGrp && !pGlossary)
717 rStatGlossaries.PutGroupDoc(pGlos);
718 }
719
GetMacros(const String & rShortName,SvxMacro & rStart,SvxMacro & rEnd,SwTextBlocks * pGlossary)720 void SwGlossaryHdl::GetMacros( const String &rShortName,
721 SvxMacro& rStart,
722 SvxMacro& rEnd,
723 SwTextBlocks *pGlossary )
724 {
725 SwTextBlocks *pGlos = pGlossary ? pGlossary
726 : pCurGrp ? pCurGrp
727 : rStatGlossaries.GetGroupDoc(aCurGrp);
728 sal_uInt16 nIndex = pGlos->GetIndex( rShortName );
729 if( nIndex != USHRT_MAX )
730 {
731 SvxMacroTableDtor aMacroTbl;
732 if( pGlos->GetMacroTable( nIndex, aMacroTbl ) )
733 {
734 SvxMacro *pMacro = aMacroTbl.Get( SW_EVENT_START_INS_GLOSSARY );
735 if( pMacro )
736 rStart = *pMacro;
737
738 pMacro = aMacroTbl.Get( SW_EVENT_END_INS_GLOSSARY );
739 if( pMacro )
740 rEnd = *pMacro;
741 }
742 }
743
744 if( !pCurGrp && !pGlossary )
745 rStatGlossaries.PutGroupDoc( pGlos );
746 }
747
748
749 /*------------------------------------------------------------------------
750 Beschreibung: ctor, dtor
751 ------------------------------------------------------------------------*/
752
753
SwGlossaryHdl(SfxViewFrame * pVwFrm,SwWrtShell * pSh)754 SwGlossaryHdl::SwGlossaryHdl(SfxViewFrame* pVwFrm, SwWrtShell *pSh)
755 : rStatGlossaries( *::GetGlossaries() ),
756 aCurGrp( rStatGlossaries.GetDefName() ),
757 pViewFrame( pVwFrm ),
758 pWrtShell( pSh ),
759 pCurGrp( 0 )
760 {
761 }
762
763
~SwGlossaryHdl()764 SwGlossaryHdl::~SwGlossaryHdl()
765 {
766 if( pCurGrp )
767 rStatGlossaries.PutGroupDoc( pCurGrp );
768 }
769
770 /*------------------------------------------------------------------------
771 Beschreibung: Umbenennen eines Textbausteines
772 ------------------------------------------------------------------------*/
773
774
Rename(const String & rOldShort,const String & rNewShortName,const String & rNewName)775 sal_Bool SwGlossaryHdl::Rename(const String& rOldShort, const String& rNewShortName,
776 const String& rNewName )
777 {
778 sal_Bool bRet = sal_False;
779 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
780 : rStatGlossaries.GetGroupDoc(aCurGrp);
781 if(pGlossary)
782 {
783 if(!ConvertToNew(*pGlossary))
784 return sal_False;
785
786 sal_uInt16 nIdx = pGlossary->GetIndex( rOldShort );
787 sal_uInt16 nOldLongIdx = pGlossary->GetLongIndex( rNewName );
788 sal_uInt16 nOldIdx = pGlossary->GetIndex( rNewShortName );
789
790 if( nIdx != USHRT_MAX &&
791 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
792 (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
793 {
794 String aNewShort( rNewShortName );
795 String aNewName( rNewName );
796 pGlossary->Rename( nIdx, &aNewShort, &aNewName );
797 bRet = pGlossary->GetError() == 0;
798 }
799 if( !pCurGrp )
800 rStatGlossaries.PutGroupDoc(pGlossary);
801 }
802 return bRet;
803 }
804
805
IsReadOnly(const String * pGrpNm) const806 sal_Bool SwGlossaryHdl::IsReadOnly( const String* pGrpNm ) const
807 {
808 SwTextBlocks *pGlossary = 0;
809
810 if (pGrpNm)
811 pGlossary = rStatGlossaries.GetGroupDoc( *pGrpNm );
812 else if (pCurGrp)
813 pGlossary = pCurGrp;
814 else
815 pGlossary = rStatGlossaries.GetGroupDoc(aCurGrp);
816
817 sal_Bool bRet = pGlossary ? pGlossary->IsReadOnly() : sal_True;
818 if( pGrpNm || !pCurGrp )
819 delete pGlossary;
820 return bRet;
821 }
822
823
IsOld() const824 sal_Bool SwGlossaryHdl::IsOld() const
825 {
826 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
827 : rStatGlossaries.GetGroupDoc(aCurGrp);
828 sal_Bool bRet = pGlossary ? pGlossary->IsOld() : sal_False;
829 if( !pCurGrp )
830 delete pGlossary;
831 return bRet;
832 }
833
834 /*-----------------09.06.97 16:15-------------------
835 Gruppe ohne Pfadindex finden
836 --------------------------------------------------*/
FindGroupName(String & rGroup)837 sal_Bool SwGlossaryHdl::FindGroupName(String & rGroup)
838 {
839 return rStatGlossaries.FindGroupName(rGroup);
840 }
841
842 /* -----------------29.07.99 08:34-------------------
843
844 --------------------------------------------------*/
CopyToClipboard(SwWrtShell & rSh,const String & rShortName)845 sal_Bool SwGlossaryHdl::CopyToClipboard(SwWrtShell& rSh, const String& rShortName)
846 {
847 SwTextBlocks *pGlossary = pCurGrp ? pCurGrp
848 : rStatGlossaries.GetGroupDoc(aCurGrp);
849
850 SwTransferable* pTransfer = new SwTransferable( rSh );
851 /*??*/uno::Reference<
852 datatransfer::XTransferable > xRef( pTransfer );
853
854 int nRet = pTransfer->CopyGlossary( *pGlossary, rShortName );
855 if( !pCurGrp )
856 rStatGlossaries.PutGroupDoc( pGlossary );
857 return 0 != nRet;
858 }
859
ImportGlossaries(const String & rName)860 sal_Bool SwGlossaryHdl::ImportGlossaries( const String& rName )
861 {
862 sal_Bool bRet = sal_False;
863 if( rName.Len() )
864 {
865 const SfxFilter* pFilter = 0;
866 SfxMedium* pMed = new SfxMedium( rName, STREAM_READ, sal_True, 0, 0 );
867 SfxFilterMatcher aMatcher( String::CreateFromAscii("swriter") );
868 pMed->UseInteractionHandler( sal_True );
869 if( !aMatcher.GuessFilter( *pMed, &pFilter, sal_False ) )
870 {
871 SwTextBlocks *pGlossary;
872 pMed->SetFilter( pFilter );
873 Reader* pR = SwReaderWriter::GetReader( pFilter->GetUserData() );
874 if( pR && 0 != ( pGlossary = pCurGrp ? pCurGrp
875 : rStatGlossaries.GetGroupDoc(aCurGrp)) )
876 {
877 SwReader aReader( *pMed, rName );
878 if( aReader.HasGlossaries( *pR ) )
879 {
880 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
881 bRet = aReader.ReadGlossaries( *pR, *pGlossary,
882 pCfg->IsSaveRelFile() );
883 }
884 }
885 }
886 DELETEZ(pMed);
887 }
888 return bRet;
889 }
890
891 /* vim: set noet sw=4 ts=4: */
892