Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <map>
21 : #include <optasian.hxx>
22 : #include <editeng/langitem.hxx>
23 : #include <editeng/unolingu.hxx>
24 : #include <optasian.hrc>
25 : #include <dialmgr.hxx>
26 : #include <cuires.hrc>
27 : #include <i18nlangtag/mslangid.hxx>
28 : #include <tools/shl.hxx>
29 : #include <svl/asiancfg.hxx>
30 : #include <com/sun/star/lang/Locale.hpp>
31 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
33 : #include <com/sun/star/beans/XPropertySet.hpp>
34 : #include <sfx2/viewfrm.hxx>
35 : #include <sfx2/objsh.hxx>
36 : #include <vcl/svapp.hxx>
37 : #include <comphelper/processfactory.hxx>
38 : #include <unotools/localedatawrapper.hxx>
39 :
40 : using namespace com::sun::star::uno;
41 : using namespace com::sun::star::lang;
42 : using namespace com::sun::star::i18n;
43 : using namespace com::sun::star::frame;
44 : using namespace com::sun::star::beans;
45 :
46 : const sal_Char cIsKernAsianPunctuation[] = "IsKernAsianPunctuation";
47 : const sal_Char cCharacterCompressionType[] = "CharacterCompressionType";
48 :
49 : struct SvxForbiddenChars_Impl
50 : {
51 : ~SvxForbiddenChars_Impl();
52 :
53 : sal_Bool bRemoved;
54 : ForbiddenCharacters* pCharacters;
55 : };
56 :
57 0 : SvxForbiddenChars_Impl::~SvxForbiddenChars_Impl()
58 : {
59 0 : delete pCharacters;
60 0 : }
61 :
62 : typedef ::std::map< LanguageType, SvxForbiddenChars_Impl* > SvxForbiddenCharacterMap_Impl;
63 :
64 : struct SvxAsianLayoutPage_Impl
65 : {
66 : SvxAsianConfig aConfig;
67 0 : SvxAsianLayoutPage_Impl() {}
68 :
69 : ~SvxAsianLayoutPage_Impl();
70 :
71 : Reference< XForbiddenCharacters > xForbidden;
72 : Reference< XPropertySet > xPrSet;
73 : Reference< XPropertySetInfo > xPrSetInfo;
74 : SvxForbiddenCharacterMap_Impl aChangedLanguagesMap;
75 :
76 : sal_Bool hasForbiddenCharacters(LanguageType eLang);
77 : SvxForbiddenChars_Impl* getForbiddenCharacters(LanguageType eLang);
78 : void addForbiddenCharacters(LanguageType eLang, ForbiddenCharacters* pForbidden);
79 : };
80 :
81 0 : SvxAsianLayoutPage_Impl::~SvxAsianLayoutPage_Impl()
82 : {
83 0 : SvxForbiddenCharacterMap_Impl::iterator it;
84 0 : for( it = aChangedLanguagesMap.begin(); it != aChangedLanguagesMap.end(); ++it )
85 : {
86 0 : delete it->second;
87 : }
88 0 : }
89 :
90 0 : sal_Bool SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang)
91 : {
92 0 : return aChangedLanguagesMap.count( eLang );
93 : }
94 :
95 0 : SvxForbiddenChars_Impl* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang)
96 : {
97 0 : SvxForbiddenCharacterMap_Impl::iterator it = aChangedLanguagesMap.find( eLang );
98 : DBG_ASSERT( ( it != aChangedLanguagesMap.end() ), "language not available");
99 0 : if( it != aChangedLanguagesMap.end() )
100 0 : return it->second;
101 0 : return 0;
102 : }
103 :
104 0 : void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
105 : LanguageType eLang, ForbiddenCharacters* pForbidden)
106 : {
107 0 : SvxForbiddenCharacterMap_Impl::iterator itOld = aChangedLanguagesMap.find( eLang );
108 0 : if( itOld == aChangedLanguagesMap.end() )
109 : {
110 0 : SvxForbiddenChars_Impl* pChar = new SvxForbiddenChars_Impl;
111 0 : pChar->bRemoved = 0 == pForbidden;
112 0 : pChar->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
113 0 : aChangedLanguagesMap.insert( ::std::make_pair( eLang, pChar ) );
114 : }
115 : else
116 : {
117 0 : itOld->second->bRemoved = 0 == pForbidden;
118 0 : delete itOld->second->pCharacters;
119 0 : itOld->second->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
120 : }
121 0 : }
122 :
123 : static LanguageType eLastUsedLanguageTypeForForbiddenCharacters = USHRT_MAX;
124 :
125 0 : SvxAsianLayoutPage::SvxAsianLayoutPage( Window* pParent, const SfxItemSet& rSet ) :
126 0 : SfxTabPage(pParent, CUI_RES( RID_SVXPAGE_ASIAN_LAYOUT ), rSet),
127 0 : aKerningGB( this, CUI_RES(GB_KERNING )),
128 0 : aCharKerningRB( this, CUI_RES(RB_CHAR_KERNING )),
129 0 : aCharPunctKerningRB( this, CUI_RES(RB_CHAR_PUNCT )),
130 0 : aCharDistGB( this, CUI_RES(GB_CHAR_DIST )),
131 0 : aNoCompressionRB( this, CUI_RES(RB_NO_COMP )),
132 0 : aPunctCompressionRB( this, CUI_RES(RB_PUNCT_COMP )),
133 0 : aPunctKanaCompressionRB(this, CUI_RES(RB_PUNCT_KANA_COMP )),
134 0 : aStartEndGB( this, CUI_RES(GB_START_END )),
135 0 : aLanguageFT( this, CUI_RES(FT_LANGUAGE )),
136 0 : aLanguageLB( this, CUI_RES(LB_LANGUAGE )),
137 0 : aStandardCB( this, CUI_RES(CB_STANDARD )),
138 0 : aStartFT( this, CUI_RES(FT_START )),
139 0 : aStartED( this, CUI_RES(ED_START )),
140 0 : aEndFT( this, CUI_RES(FT_END )),
141 0 : aEndED( this, CUI_RES(ED_END )),
142 0 : aHintFT( this, CUI_RES(FT_HINT )),
143 0 : pImpl(new SvxAsianLayoutPage_Impl)
144 : {
145 0 : FreeResource();
146 0 : LanguageHdl(&aLanguageLB);
147 0 : aLanguageLB.SetSelectHdl(LINK(this, SvxAsianLayoutPage, LanguageHdl));
148 0 : aStandardCB.SetClickHdl(LINK(this, SvxAsianLayoutPage, ChangeStandardHdl));
149 0 : Link aLk(LINK(this, SvxAsianLayoutPage, ModifyHdl));
150 0 : aStartED.SetModifyHdl(aLk);
151 0 : aEndED.SetModifyHdl(aLk);
152 :
153 0 : aLanguageLB.SetLanguageList( LANG_LIST_FBD_CHARS, sal_False, sal_False );
154 0 : }
155 :
156 0 : SvxAsianLayoutPage::~SvxAsianLayoutPage()
157 : {
158 0 : delete pImpl;
159 0 : }
160 :
161 0 : SfxTabPage* SvxAsianLayoutPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
162 : {
163 0 : return new SvxAsianLayoutPage(pParent, rAttrSet);
164 : }
165 :
166 0 : sal_Bool SvxAsianLayoutPage::FillItemSet( SfxItemSet& )
167 : {
168 0 : if(aCharKerningRB.IsChecked() != aCharKerningRB.GetSavedValue())
169 : {
170 0 : pImpl->aConfig.SetKerningWesternTextOnly(aCharKerningRB.IsChecked());
171 0 : OUString sPunct(cIsKernAsianPunctuation);
172 0 : if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sPunct))
173 : {
174 0 : Any aVal;
175 0 : sal_Bool bVal = !aCharKerningRB.IsChecked();
176 0 : aVal.setValue(&bVal, ::getBooleanCppuType());
177 0 : pImpl->xPrSet->setPropertyValue(sPunct, aVal);
178 0 : }
179 : }
180 :
181 0 : if(aNoCompressionRB.IsChecked() != aNoCompressionRB.GetSavedValue() ||
182 0 : aPunctCompressionRB.IsChecked() != aPunctCompressionRB.GetSavedValue())
183 : {
184 0 : sal_Int16 nSet = aNoCompressionRB.IsChecked() ? 0 :
185 0 : aPunctCompressionRB.IsChecked() ? 1 : 2;
186 0 : pImpl->aConfig.SetCharDistanceCompression(nSet);
187 0 : OUString sCompress(cCharacterCompressionType);
188 0 : if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sCompress))
189 : {
190 0 : Any aVal;
191 0 : aVal <<= nSet;
192 0 : pImpl->xPrSet->setPropertyValue(sCompress, aVal);
193 0 : }
194 : }
195 0 : pImpl->aConfig.Commit();
196 0 : if(pImpl->xForbidden.is())
197 : {
198 : try
199 : {
200 0 : SvxForbiddenCharacterMap_Impl::iterator itElem;
201 0 : for( itElem = pImpl->aChangedLanguagesMap.begin();
202 0 : itElem != pImpl->aChangedLanguagesMap.end(); ++itElem )
203 : {
204 0 : Locale aLocale( LanguageTag( itElem->first ).getLocale());
205 0 : if(itElem->second->bRemoved)
206 0 : pImpl->xForbidden->removeForbiddenCharacters( aLocale );
207 0 : else if(itElem->second->pCharacters)
208 0 : pImpl->xForbidden->setForbiddenCharacters( aLocale, *( itElem->second->pCharacters ) );
209 0 : }
210 : }
211 0 : catch (const Exception&)
212 : {
213 : OSL_FAIL("exception in XForbiddenCharacters");
214 : }
215 : }
216 0 : eLastUsedLanguageTypeForForbiddenCharacters = aLanguageLB.GetSelectLanguage();
217 :
218 0 : return sal_False;
219 : }
220 :
221 0 : void SvxAsianLayoutPage::Reset( const SfxItemSet& )
222 : {
223 0 : SfxViewFrame* pCurFrm = SfxViewFrame::Current();
224 0 : SfxObjectShell* pDocSh = pCurFrm ? pCurFrm->GetObjectShell() : 0;
225 0 : Reference< XModel > xModel;
226 0 : if(pDocSh)
227 0 : xModel = pDocSh->GetModel();
228 0 : Reference<XMultiServiceFactory> xFact(xModel, UNO_QUERY);
229 0 : if(xFact.is())
230 : {
231 0 : pImpl->xPrSet = Reference<XPropertySet>(
232 0 : xFact->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
233 : }
234 0 : if( pImpl->xPrSet.is() )
235 0 : pImpl->xPrSetInfo = pImpl->xPrSet->getPropertySetInfo();
236 0 : OUString sForbidden("ForbiddenCharacters");
237 0 : sal_Bool bKernWesternText = pImpl->aConfig.IsKerningWesternTextOnly();
238 0 : sal_Int16 nCompress = pImpl->aConfig.GetCharDistanceCompression();
239 0 : if(pImpl->xPrSetInfo.is())
240 : {
241 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sForbidden))
242 : {
243 0 : Any aForbidden = pImpl->xPrSet->getPropertyValue(sForbidden);
244 0 : aForbidden >>= pImpl->xForbidden;
245 : }
246 0 : OUString sCompress(cCharacterCompressionType);
247 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sCompress))
248 : {
249 0 : Any aVal = pImpl->xPrSet->getPropertyValue(sCompress);
250 0 : aVal >>= nCompress;
251 : }
252 0 : OUString sPunct(cIsKernAsianPunctuation);
253 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sPunct))
254 : {
255 0 : Any aVal = pImpl->xPrSet->getPropertyValue(sPunct);
256 0 : bKernWesternText = !*(sal_Bool*)aVal.getValue();
257 0 : }
258 : }
259 : else
260 : {
261 0 : aStartEndGB.Enable(sal_False);
262 0 : aLanguageFT.Enable(sal_False);
263 0 : aLanguageLB.Enable(sal_False);
264 0 : aStandardCB.Enable(sal_False);
265 0 : aStartFT.Enable(sal_False);
266 0 : aStartED.Enable(sal_False);
267 0 : aEndFT.Enable(sal_False);
268 0 : aEndED.Enable(sal_False);
269 0 : aHintFT.Enable(sal_False);
270 : }
271 0 : if(bKernWesternText)
272 0 : aCharKerningRB.Check(sal_True);
273 : else
274 0 : aCharPunctKerningRB.Check(sal_True);
275 0 : switch(nCompress)
276 : {
277 0 : case 0 : aNoCompressionRB.Check(); break;
278 0 : case 1 : aPunctCompressionRB.Check(); break;
279 0 : default: aPunctKanaCompressionRB.Check();
280 : }
281 0 : aCharKerningRB.SaveValue();
282 0 : aNoCompressionRB.SaveValue();
283 0 : aPunctCompressionRB.SaveValue();
284 0 : aPunctKanaCompressionRB.SaveValue();
285 :
286 0 : aLanguageLB.SelectEntryPos(0);
287 : //preselect the system language in the box - if available
288 0 : if(USHRT_MAX == eLastUsedLanguageTypeForForbiddenCharacters)
289 : {
290 : eLastUsedLanguageTypeForForbiddenCharacters =
291 0 : Application::GetSettings().GetLanguageTag().getLanguageType();
292 0 : if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters))
293 0 : eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_SIMPLIFIED;
294 0 : else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters))
295 0 : eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_TRADITIONAL;
296 : }
297 0 : aLanguageLB.SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters );
298 0 : LanguageHdl(&aLanguageLB);
299 0 : }
300 :
301 0 : IMPL_LINK_NOARG(SvxAsianLayoutPage, LanguageHdl)
302 : {
303 : //set current value
304 0 : LanguageType eSelectLanguage = aLanguageLB.GetSelectLanguage();
305 0 : LanguageTag aLanguageTag( eSelectLanguage);
306 0 : Locale aLocale( aLanguageTag.getLocale());
307 :
308 0 : OUString sStart, sEnd;
309 : sal_Bool bAvail;
310 0 : if(pImpl->xForbidden.is())
311 : {
312 0 : bAvail = pImpl->hasForbiddenCharacters(eSelectLanguage);
313 0 : if(bAvail)
314 : {
315 0 : SvxForbiddenChars_Impl* pElement = pImpl->getForbiddenCharacters(eSelectLanguage);
316 0 : if(pElement->bRemoved || !pElement->pCharacters)
317 : {
318 0 : bAvail = sal_False;
319 : }
320 : else
321 : {
322 0 : sStart = pElement->pCharacters->beginLine;
323 0 : sEnd = pElement->pCharacters->endLine;
324 : }
325 : }
326 : else
327 : {
328 : try
329 : {
330 0 : bAvail = pImpl->xForbidden->hasForbiddenCharacters(aLocale);
331 0 : if(bAvail)
332 : {
333 0 : ForbiddenCharacters aForbidden = pImpl->xForbidden->getForbiddenCharacters( aLocale );
334 0 : sStart = aForbidden.beginLine;
335 0 : sEnd = aForbidden.endLine;
336 : }
337 : }
338 0 : catch (const Exception&)
339 : {
340 : OSL_FAIL("exception in XForbiddenCharacters");
341 : }
342 : }
343 : }
344 : else
345 : {
346 0 : bAvail = pImpl->aConfig.GetStartEndChars( aLocale, sStart, sEnd );
347 : }
348 0 : if(!bAvail)
349 : {
350 0 : LocaleDataWrapper aWrap( aLanguageTag );
351 0 : ForbiddenCharacters aForbidden = aWrap.getForbiddenCharacters();
352 0 : sStart = aForbidden.beginLine;
353 0 : sEnd = aForbidden.endLine;
354 : }
355 0 : aStandardCB.Check(!bAvail);
356 0 : aStartED.Enable(bAvail);
357 0 : aEndED.Enable(bAvail);
358 0 : aStartFT.Enable(bAvail);
359 0 : aEndFT.Enable(bAvail);
360 0 : aStartED.SetText(sStart);
361 0 : aEndED.SetText(sEnd);
362 :
363 0 : return 0;
364 : }
365 :
366 0 : IMPL_LINK(SvxAsianLayoutPage, ChangeStandardHdl, CheckBox*, pBox)
367 : {
368 0 : sal_Bool bCheck = pBox->IsChecked();
369 0 : aStartED.Enable(!bCheck);
370 0 : aEndED.Enable(!bCheck);
371 0 : aStartFT.Enable(!bCheck);
372 0 : aEndFT.Enable(!bCheck);
373 :
374 0 : ModifyHdl(&aStartED);
375 0 : return 0;
376 : }
377 :
378 0 : IMPL_LINK(SvxAsianLayoutPage, ModifyHdl, Edit*, pEdit)
379 : {
380 0 : LanguageType eSelectLanguage = aLanguageLB.GetSelectLanguage();
381 0 : Locale aLocale( LanguageTag( eSelectLanguage ).getLocale());
382 0 : OUString sStart = aStartED.GetText();
383 0 : OUString sEnd = aEndED.GetText();
384 0 : sal_Bool bEnable = pEdit->IsEnabled();
385 0 : if(pImpl->xForbidden.is())
386 : {
387 : try
388 : {
389 0 : if(bEnable)
390 : {
391 0 : ForbiddenCharacters aSet;
392 0 : aSet.beginLine = sStart;
393 0 : aSet.endLine = sEnd;
394 0 : pImpl->addForbiddenCharacters(eSelectLanguage, &aSet);
395 : }
396 : else
397 0 : pImpl->addForbiddenCharacters(eSelectLanguage, 0);
398 : }
399 0 : catch (const Exception&)
400 : {
401 : OSL_FAIL("exception in XForbiddenCharacters");
402 : }
403 : }
404 0 : pImpl->aConfig.SetStartEndChars( aLocale, bEnable ? &sStart : 0, bEnable ? &sEnd : 0);
405 0 : return 0;
406 : }
407 :
408 0 : sal_uInt16* SvxAsianLayoutPage::GetRanges()
409 : {
410 : //no items are used
411 : static sal_uInt16 pAsianLayoutRanges[] = { 0 };
412 0 : return pAsianLayoutRanges;
413 0 : }
414 :
415 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|