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