Update ooo320-m1
[ooovba.git] / svx / source / options / asiancfg.cxx
blobcd1731d23d17835d765a86a6100a76ff738653f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asiancfg.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <asiancfg.hxx>
34 #include <svtools/svarray.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/lang/Locale.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <tools/debug.hxx>
41 //-----------------------------------------------------------------------------
42 using namespace utl;
43 using namespace rtl;
44 using namespace com::sun::star;
45 using namespace com::sun::star::uno;
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::lang;
49 #define C2U(cChar) OUString::createFromAscii(cChar)
50 const sal_Char sStartEndCharacters[] = "StartEndCharacters";
51 const sal_Char sStartCharacters[] = "StartCharacters";
52 const sal_Char sEndCharacters[] = "EndCharacters";
54 //-----------------------------------------------------------------------------
55 struct SvxForbiddenStruct_Impl
57 Locale aLocale;
58 OUString sStartChars;
59 OUString sEndChars;
61 //-----------------------------------------------------------------------------
62 typedef SvxForbiddenStruct_Impl* SvxForbiddenStruct_ImplPtr;
63 SV_DECL_PTRARR_DEL(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr, 2, 2)
64 SV_IMPL_PTRARR(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr);
65 //-----------------------------------------------------------------------------
66 struct SvxAsianConfig_Impl
68 sal_Bool bKerningWesternTextOnly;
69 sal_Int16 nCharDistanceCompression;
71 SvxForbiddenStructArr aForbiddenArr;
73 SvxAsianConfig_Impl() :
74 bKerningWesternTextOnly(sal_True),
75 nCharDistanceCompression(0) {}
77 /* -----------------------------16.01.01 15:36--------------------------------
79 ---------------------------------------------------------------------------*/
80 Sequence<OUString> lcl_GetPropertyNames()
82 Sequence<OUString> aNames(2);
83 OUString* pNames = aNames.getArray();
84 pNames[0] = C2U("IsKerningWesternTextOnly");
85 pNames[1] = C2U("CompressCharacterDistance");
86 return aNames;;
88 // ---------------------------------------------------------------------------
89 SvxAsianConfig::SvxAsianConfig(sal_Bool bEnableNotify) :
90 utl::ConfigItem(C2U("Office.Common/AsianLayout")),
91 pImpl(new SvxAsianConfig_Impl)
93 if(bEnableNotify)
94 EnableNotification(lcl_GetPropertyNames());
95 Load();
97 /* -----------------------------16.01.01 15:36--------------------------------
99 ---------------------------------------------------------------------------*/
100 SvxAsianConfig::~SvxAsianConfig()
102 delete pImpl;
104 /* -----------------------------17.01.01 09:57--------------------------------
106 ---------------------------------------------------------------------------*/
107 void SvxAsianConfig::Load()
109 Sequence<Any> aValues = GetProperties(lcl_GetPropertyNames());
110 const Any* pValues = aValues.getConstArray();
111 if(pValues[0].hasValue())
112 pImpl->bKerningWesternTextOnly = *(sal_Bool*) pValues[0].getValue();
113 pValues[1] >>= pImpl->nCharDistanceCompression;
115 pImpl->aForbiddenArr.DeleteAndDestroy(0, pImpl->aForbiddenArr.Count());
116 OUString sPropPrefix(C2U(sStartEndCharacters));
117 Sequence<OUString> aNodes = GetNodeNames(sPropPrefix);
119 Sequence<OUString> aPropNames(aNodes.getLength() * 2);
120 OUString* pNames = aPropNames.getArray();
121 sal_Int32 nName = 0;
122 sPropPrefix += C2U("/");
123 sal_Int32 nNode;
124 const OUString* pNodes = aNodes.getConstArray();
125 for(nNode = 0; nNode < aNodes.getLength(); nNode++)
127 OUString sStart(sPropPrefix);
128 sStart += pNodes[nNode];
129 sStart += C2U("/");
130 pNames[nName] = sStart; pNames[nName++] += C2U("StartCharacters");
131 pNames[nName] = sStart; pNames[nName++] += C2U("EndCharacters");
133 Sequence<Any> aNodeValues = GetProperties(aPropNames);
134 const Any* pNodeValues = aNodeValues.getConstArray();
135 nName = 0;
136 for(nNode = 0; nNode < aNodes.getLength(); nNode++)
138 SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl;
139 pInsert->aLocale.Language = pNodes[nNode].copy(0, 2);
140 DBG_ASSERT(pInsert->aLocale.Language.getLength(), "illegal language");
141 pInsert->aLocale.Country = pNodes[nNode].copy(3, 2);
143 pNodeValues[nName++] >>= pInsert->sStartChars;
144 pNodeValues[nName++] >>= pInsert->sEndChars;
145 pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count());
148 /* -----------------------------17.01.01 09:57--------------------------------
150 ---------------------------------------------------------------------------*/
151 void SvxAsianConfig::Notify( const Sequence<OUString>& )
153 Load();
155 /* -----------------------------16.01.01 15:36--------------------------------
157 ---------------------------------------------------------------------------*/
158 void SvxAsianConfig::Commit()
160 Sequence<Any> aValues(2);
161 Any* pValues = aValues.getArray();
162 pValues[0].setValue(&pImpl->bKerningWesternTextOnly, ::getBooleanCppuType());
163 pValues[1] <<= pImpl->nCharDistanceCompression;
164 PutProperties(lcl_GetPropertyNames(), aValues);
167 OUString sNode(C2U(sStartEndCharacters));
168 if(!pImpl->aForbiddenArr.Count())
169 ClearNodeSet(sNode);
170 else
172 Sequence<PropertyValue> aSetValues(2 * pImpl->aForbiddenArr.Count());
173 PropertyValue* pSetValues = aSetValues.getArray();
174 sal_Int32 nSetValue = 0;
175 const OUString sStartChars(C2U(sStartCharacters));
176 const OUString sEndChars(C2U(sEndCharacters));
177 for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
179 OUString sPrefix(sNode);
180 sPrefix += C2U("/");
181 sPrefix += pImpl->aForbiddenArr[i]->aLocale.Language;
182 DBG_ASSERT(pImpl->aForbiddenArr[i]->aLocale.Language.getLength(), "illegal language");
183 sPrefix += C2U("-");
184 sPrefix += pImpl->aForbiddenArr[i]->aLocale.Country;
185 sPrefix += C2U("/");
186 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sStartChars;
187 pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sStartChars;
188 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sEndChars;
189 pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sEndChars;
191 ReplaceSetProperties(sNode, aSetValues);
194 /* -----------------------------16.01.01 15:36--------------------------------
196 ---------------------------------------------------------------------------*/
197 sal_Bool SvxAsianConfig::IsKerningWesternTextOnly() const
199 return pImpl->bKerningWesternTextOnly;
201 /* -----------------------------16.01.01 15:36--------------------------------
203 ---------------------------------------------------------------------------*/
204 void SvxAsianConfig::SetKerningWesternTextOnly(sal_Bool bSet)
206 pImpl->bKerningWesternTextOnly = bSet;
207 SetModified();
209 /* -----------------------------16.01.01 15:36--------------------------------
211 ---------------------------------------------------------------------------*/
212 sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const
214 return pImpl->nCharDistanceCompression;
216 /* -----------------------------16.01.01 15:36--------------------------------
218 ---------------------------------------------------------------------------*/
219 void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 nSet)
221 DBG_ASSERT(nSet >= 0 && nSet < 3, "compression value illegal");
222 SetModified();
223 pImpl->nCharDistanceCompression = nSet;
225 /* -----------------------------16.01.01 15:36--------------------------------
227 ---------------------------------------------------------------------------*/
228 uno::Sequence<lang::Locale> SvxAsianConfig::GetStartEndCharLocales()
230 Sequence<Locale> aRet(pImpl->aForbiddenArr.Count());
231 Locale* pRet = aRet.getArray();
232 for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
234 pRet[i] = pImpl->aForbiddenArr[i]->aLocale;
236 return aRet;
238 /* -----------------------------16.01.01 15:36--------------------------------
240 ---------------------------------------------------------------------------*/
241 sal_Bool SvxAsianConfig::GetStartEndChars( const Locale& rLocale,
242 OUString& rStartChars,
243 OUString& rEndChars )
245 for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
247 if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language &&
248 rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country)
250 rStartChars = pImpl->aForbiddenArr[i]->sStartChars;
251 rEndChars = pImpl->aForbiddenArr[i]->sEndChars;
252 return sal_True;
255 return sal_False;
257 /* -----------------------------16.01.01 15:36--------------------------------
259 ---------------------------------------------------------------------------*/
260 void SvxAsianConfig::SetStartEndChars( const Locale& rLocale,
261 const OUString* pStartChars,
262 const OUString* pEndChars )
264 sal_Bool bFound = sal_False;
265 for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++)
267 if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language &&
268 rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country)
270 if(pStartChars && pEndChars)
272 pImpl->aForbiddenArr[i]->sStartChars = *pStartChars;
273 pImpl->aForbiddenArr[i]->sEndChars = *pEndChars;
275 else
276 pImpl->aForbiddenArr.DeleteAndDestroy(i, 1);
277 bFound = sal_True;
280 if(!bFound && pStartChars && pEndChars)
282 SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl;
283 pInsert->aLocale = rLocale;
284 pInsert->sStartChars = *pStartChars;
285 pInsert->sEndChars = *pEndChars;
286 pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count());
288 #ifdef DBG_UTIL
289 else if(!bFound)
290 DBG_ERROR("attempt to clear unavailable data");
291 #endif
292 SetModified();