1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asiancfg.cxx,v $
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 //-----------------------------------------------------------------------------
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
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");
88 // ---------------------------------------------------------------------------
89 SvxAsianConfig::SvxAsianConfig(sal_Bool bEnableNotify
) :
90 utl::ConfigItem(C2U("Office.Common/AsianLayout")),
91 pImpl(new SvxAsianConfig_Impl
)
94 EnableNotification(lcl_GetPropertyNames());
97 /* -----------------------------16.01.01 15:36--------------------------------
99 ---------------------------------------------------------------------------*/
100 SvxAsianConfig::~SvxAsianConfig()
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();
122 sPropPrefix
+= C2U("/");
124 const OUString
* pNodes
= aNodes
.getConstArray();
125 for(nNode
= 0; nNode
< aNodes
.getLength(); nNode
++)
127 OUString
sStart(sPropPrefix
);
128 sStart
+= pNodes
[nNode
];
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();
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
>& )
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())
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
);
181 sPrefix
+= pImpl
->aForbiddenArr
[i
]->aLocale
.Language
;
182 DBG_ASSERT(pImpl
->aForbiddenArr
[i
]->aLocale
.Language
.getLength(), "illegal language");
184 sPrefix
+= pImpl
->aForbiddenArr
[i
]->aLocale
.Country
;
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
;
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");
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
;
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
;
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
;
276 pImpl
->aForbiddenArr
.DeleteAndDestroy(i
, 1);
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());
290 DBG_ERROR("attempt to clear unavailable data");