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