xref: /aoo41x/main/svl/source/config/asiancfg.cxx (revision 40df464e)
1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*40df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*40df464eSAndrew Rist  * distributed with this work for additional information
6*40df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*40df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist  * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*40df464eSAndrew Rist  *
11*40df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist  *
13*40df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist  * software distributed under the License is distributed on an
15*40df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*40df464eSAndrew Rist  * specific language governing permissions and limitations
18*40df464eSAndrew Rist  * under the License.
19*40df464eSAndrew Rist  *
20*40df464eSAndrew Rist  *************************************************************/
21*40df464eSAndrew Rist 
22*40df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svl/asiancfg.hxx>
28cdf0e10cSrcweir #include <svl/svarray.hxx>
29cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
31cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //-----------------------------------------------------------------------------
36cdf0e10cSrcweir using namespace utl;
37cdf0e10cSrcweir using namespace rtl;
38cdf0e10cSrcweir using namespace com::sun::star;
39cdf0e10cSrcweir using namespace com::sun::star::uno;
40cdf0e10cSrcweir using namespace com::sun::star::beans;
41cdf0e10cSrcweir using namespace com::sun::star::lang;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
44cdf0e10cSrcweir const sal_Char sStartEndCharacters[] = "StartEndCharacters";
45cdf0e10cSrcweir const sal_Char sStartCharacters[] = "StartCharacters";
46cdf0e10cSrcweir const sal_Char sEndCharacters[] = "EndCharacters";
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //-----------------------------------------------------------------------------
49cdf0e10cSrcweir struct SvxForbiddenStruct_Impl
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	Locale 		aLocale;
52cdf0e10cSrcweir 	OUString	sStartChars;
53cdf0e10cSrcweir 	OUString	sEndChars;
54cdf0e10cSrcweir };
55cdf0e10cSrcweir //-----------------------------------------------------------------------------
56cdf0e10cSrcweir typedef SvxForbiddenStruct_Impl* SvxForbiddenStruct_ImplPtr;
57cdf0e10cSrcweir SV_DECL_PTRARR_DEL(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr, 2, 2)
58cdf0e10cSrcweir SV_IMPL_PTRARR(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr);
59cdf0e10cSrcweir //-----------------------------------------------------------------------------
60cdf0e10cSrcweir struct SvxAsianConfig_Impl
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	sal_Bool 	bKerningWesternTextOnly;
63cdf0e10cSrcweir 	sal_Int16	nCharDistanceCompression;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	SvxForbiddenStructArr	aForbiddenArr;
66cdf0e10cSrcweir 
SvxAsianConfig_ImplSvxAsianConfig_Impl67cdf0e10cSrcweir 	SvxAsianConfig_Impl() :
68cdf0e10cSrcweir 		bKerningWesternTextOnly(sal_True),
69cdf0e10cSrcweir 		nCharDistanceCompression(0) {}
70cdf0e10cSrcweir };
71cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
72cdf0e10cSrcweir 
73cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
lcl_GetPropertyNames()74cdf0e10cSrcweir Sequence<OUString> lcl_GetPropertyNames()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	Sequence<OUString> aNames(2);
77cdf0e10cSrcweir 	OUString* pNames = aNames.getArray();
78cdf0e10cSrcweir 	pNames[0] = C2U("IsKerningWesternTextOnly");
79cdf0e10cSrcweir 	pNames[1] = C2U("CompressCharacterDistance");
80cdf0e10cSrcweir 	return aNames;;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir // ---------------------------------------------------------------------------
SvxAsianConfig(sal_Bool bEnableNotify)83cdf0e10cSrcweir SvxAsianConfig::SvxAsianConfig(sal_Bool bEnableNotify) :
84cdf0e10cSrcweir 	utl::ConfigItem(C2U("Office.Common/AsianLayout")),
85cdf0e10cSrcweir 	pImpl(new SvxAsianConfig_Impl)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	if(bEnableNotify)
88cdf0e10cSrcweir 		EnableNotification(lcl_GetPropertyNames());
89cdf0e10cSrcweir 	Load();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
92cdf0e10cSrcweir 
93cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
~SvxAsianConfig()94cdf0e10cSrcweir SvxAsianConfig::~SvxAsianConfig()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	delete pImpl;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
99cdf0e10cSrcweir 
100cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Load()101cdf0e10cSrcweir void SvxAsianConfig::Load()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	Sequence<Any> aValues = GetProperties(lcl_GetPropertyNames());
104cdf0e10cSrcweir 	const Any* pValues = aValues.getConstArray();
105cdf0e10cSrcweir 	if(pValues[0].hasValue())
106cdf0e10cSrcweir 		pImpl->bKerningWesternTextOnly = *(sal_Bool*) pValues[0].getValue();
107cdf0e10cSrcweir 	pValues[1] >>= pImpl->nCharDistanceCompression;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	pImpl->aForbiddenArr.DeleteAndDestroy(0, pImpl->aForbiddenArr.Count());
110cdf0e10cSrcweir 	OUString sPropPrefix(C2U(sStartEndCharacters));
111cdf0e10cSrcweir 	Sequence<OUString> aNodes = GetNodeNames(sPropPrefix);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	Sequence<OUString> aPropNames(aNodes.getLength() * 2);
114cdf0e10cSrcweir 	OUString* pNames = aPropNames.getArray();
115cdf0e10cSrcweir 	sal_Int32 nName = 0;
116cdf0e10cSrcweir 	sPropPrefix += C2U("/");
117cdf0e10cSrcweir 	sal_Int32 nNode;
118cdf0e10cSrcweir 	const OUString* pNodes = aNodes.getConstArray();
119cdf0e10cSrcweir 	for(nNode = 0; nNode < aNodes.getLength(); nNode++)
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		OUString sStart(sPropPrefix);
122cdf0e10cSrcweir 		sStart += pNodes[nNode];
123cdf0e10cSrcweir 		sStart += C2U("/");
124cdf0e10cSrcweir 		pNames[nName] = sStart; 	pNames[nName++] += C2U("StartCharacters");
125cdf0e10cSrcweir 		pNames[nName] = sStart; 	pNames[nName++] += C2U("EndCharacters");
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 	Sequence<Any> aNodeValues = GetProperties(aPropNames);
128cdf0e10cSrcweir 	const Any* pNodeValues = aNodeValues.getConstArray();
129cdf0e10cSrcweir 	nName = 0;
130cdf0e10cSrcweir 	for(nNode = 0; nNode < aNodes.getLength(); nNode++)
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl;
133cdf0e10cSrcweir 		pInsert->aLocale.Language = pNodes[nNode].copy(0, 2);
134cdf0e10cSrcweir 		DBG_ASSERT(pInsert->aLocale.Language.getLength(), "illegal language");
135cdf0e10cSrcweir 		pInsert->aLocale.Country = pNodes[nNode].copy(3, 2);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		pNodeValues[nName++] >>= pInsert->sStartChars;
138cdf0e10cSrcweir 		pNodeValues[nName++] >>= pInsert->sEndChars;
139cdf0e10cSrcweir 		pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count());
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir }
142cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
143cdf0e10cSrcweir 
144cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Notify(const Sequence<OUString> &)145cdf0e10cSrcweir void 	SvxAsianConfig::Notify( const Sequence<OUString>& )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	Load();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
150cdf0e10cSrcweir 
151cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Commit()152cdf0e10cSrcweir void SvxAsianConfig::Commit()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	Sequence<Any> aValues(2);
155cdf0e10cSrcweir 	Any* pValues = aValues.getArray();
156cdf0e10cSrcweir 	pValues[0].setValue(&pImpl->bKerningWesternTextOnly, ::getBooleanCppuType());
157cdf0e10cSrcweir 	pValues[1] <<= pImpl->nCharDistanceCompression;
158cdf0e10cSrcweir 	PutProperties(lcl_GetPropertyNames(), aValues);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	OUString sNode(C2U(sStartEndCharacters));
162cdf0e10cSrcweir 	if(!pImpl->aForbiddenArr.Count())
163cdf0e10cSrcweir 		ClearNodeSet(sNode);
164cdf0e10cSrcweir 	else
165cdf0e10cSrcweir 	{
166cdf0e10cSrcweir 		Sequence<PropertyValue> aSetValues(2 * pImpl->aForbiddenArr.Count());
167cdf0e10cSrcweir 		PropertyValue* pSetValues = aSetValues.getArray();
168cdf0e10cSrcweir 		sal_Int32 nSetValue = 0;
169cdf0e10cSrcweir 		const OUString sStartChars(C2U(sStartCharacters));
170cdf0e10cSrcweir 		const OUString sEndChars(C2U(sEndCharacters));
171cdf0e10cSrcweir 		for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			OUString sPrefix(sNode);
174cdf0e10cSrcweir 			sPrefix += C2U("/");
175cdf0e10cSrcweir 			sPrefix += pImpl->aForbiddenArr[i]->aLocale.Language;
176cdf0e10cSrcweir 			DBG_ASSERT(pImpl->aForbiddenArr[i]->aLocale.Language.getLength(), "illegal language");
177cdf0e10cSrcweir 			sPrefix += C2U("-");
178cdf0e10cSrcweir 			sPrefix += pImpl->aForbiddenArr[i]->aLocale.Country;
179cdf0e10cSrcweir 			sPrefix += C2U("/");
180cdf0e10cSrcweir 			pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sStartChars;
181cdf0e10cSrcweir 			pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sStartChars;
182cdf0e10cSrcweir 			pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sEndChars;
183cdf0e10cSrcweir 			pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sEndChars;
184cdf0e10cSrcweir 		}
185cdf0e10cSrcweir 		ReplaceSetProperties(sNode, aSetValues);
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir }
188cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
189cdf0e10cSrcweir 
190cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
IsKerningWesternTextOnly() const191cdf0e10cSrcweir sal_Bool 	SvxAsianConfig::IsKerningWesternTextOnly() const
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	return pImpl->bKerningWesternTextOnly;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
196cdf0e10cSrcweir 
197cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetKerningWesternTextOnly(sal_Bool bSet)198cdf0e10cSrcweir void 		SvxAsianConfig::SetKerningWesternTextOnly(sal_Bool bSet)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	pImpl->bKerningWesternTextOnly = bSet;
201cdf0e10cSrcweir 	SetModified();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
204cdf0e10cSrcweir 
205cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetCharDistanceCompression() const206cdf0e10cSrcweir sal_Int16	SvxAsianConfig::GetCharDistanceCompression() const
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	return pImpl->nCharDistanceCompression;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
211cdf0e10cSrcweir 
212cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetCharDistanceCompression(sal_Int16 nSet)213cdf0e10cSrcweir void 		SvxAsianConfig::SetCharDistanceCompression(sal_Int16 nSet)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir 	DBG_ASSERT(nSet >= 0 && nSet < 3, "compression value illegal");
216cdf0e10cSrcweir 	SetModified();
217cdf0e10cSrcweir 	pImpl->nCharDistanceCompression = nSet;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
220cdf0e10cSrcweir 
221cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetStartEndCharLocales()222cdf0e10cSrcweir uno::Sequence<lang::Locale> SvxAsianConfig::GetStartEndCharLocales()
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	Sequence<Locale> aRet(pImpl->aForbiddenArr.Count());
225cdf0e10cSrcweir 	Locale* pRet = aRet.getArray();
226cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
227cdf0e10cSrcweir 	{
228cdf0e10cSrcweir 		pRet[i] = pImpl->aForbiddenArr[i]->aLocale;
229cdf0e10cSrcweir 	}
230cdf0e10cSrcweir 	return aRet;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
233cdf0e10cSrcweir 
234cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetStartEndChars(const Locale & rLocale,OUString & rStartChars,OUString & rEndChars)235cdf0e10cSrcweir sal_Bool	SvxAsianConfig::GetStartEndChars( const Locale& rLocale,
236cdf0e10cSrcweir 									OUString& rStartChars,
237cdf0e10cSrcweir 									OUString& rEndChars )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language &&
242cdf0e10cSrcweir 			rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country)
243cdf0e10cSrcweir 		{
244cdf0e10cSrcweir 			rStartChars = pImpl->aForbiddenArr[i]->sStartChars;
245cdf0e10cSrcweir 			rEndChars = pImpl->aForbiddenArr[i]->sEndChars;
246cdf0e10cSrcweir 			return sal_True;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 	return sal_False;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
252cdf0e10cSrcweir 
253cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetStartEndChars(const Locale & rLocale,const OUString * pStartChars,const OUString * pEndChars)254cdf0e10cSrcweir void SvxAsianConfig::SetStartEndChars( const Locale& rLocale,
255cdf0e10cSrcweir 									const OUString* pStartChars,
256cdf0e10cSrcweir 									const OUString* pEndChars )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
259cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language &&
262cdf0e10cSrcweir 			rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country)
263cdf0e10cSrcweir 		{
264cdf0e10cSrcweir 			if(pStartChars && pEndChars)
265cdf0e10cSrcweir 			{
266cdf0e10cSrcweir 				pImpl->aForbiddenArr[i]->sStartChars = *pStartChars;
267cdf0e10cSrcweir 				pImpl->aForbiddenArr[i]->sEndChars = *pEndChars;
268cdf0e10cSrcweir 			}
269cdf0e10cSrcweir 			else
270cdf0e10cSrcweir 				pImpl->aForbiddenArr.DeleteAndDestroy(i, 1);
271cdf0e10cSrcweir 			bFound = sal_True;
272cdf0e10cSrcweir 		}
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir 	if(!bFound && pStartChars && pEndChars)
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl;
277cdf0e10cSrcweir 		pInsert->aLocale = rLocale;
278cdf0e10cSrcweir 		pInsert->sStartChars = *pStartChars;
279cdf0e10cSrcweir 		pInsert->sEndChars = *pEndChars;
280cdf0e10cSrcweir 		pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count());
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir #ifdef DBG_UTIL
283cdf0e10cSrcweir 	else if(!bFound)
284cdf0e10cSrcweir 		DBG_ERROR("attempt to clear unavailable data");
285cdf0e10cSrcweir #endif
286cdf0e10cSrcweir 	SetModified();
287cdf0e10cSrcweir }
288