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