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