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 <dialmgr.hxx>
25 : #include <cuires.hrc>
26 : #include <i18nlangtag/mslangid.hxx>
27 : #include <tools/shl.hxx>
28 : #include <svl/asiancfg.hxx>
29 : #include <com/sun/star/lang/Locale.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
32 : #include <com/sun/star/beans/XPropertySet.hpp>
33 : #include <sfx2/viewfrm.hxx>
34 : #include <sfx2/objsh.hxx>
35 : #include <vcl/svapp.hxx>
36 : #include <vcl/settings.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 : SfxTabPage(pParent, "OptAsianPage", "cui/ui/optasianpage.ui", rSet),
127 0 : pImpl(new SvxAsianLayoutPage_Impl)
128 : {
129 0 : get(m_pCharKerningRB, "charkerning");
130 0 : get(m_pCharPunctKerningRB, "charpunctkerning");
131 0 : get(m_pNoCompressionRB, "nocompression");
132 0 : get(m_pPunctCompressionRB, "punctcompression");
133 0 : get(m_pPunctKanaCompressionRB, "punctkanacompression");
134 0 : get(m_pLanguageFT, "languageft");
135 0 : get(m_pLanguageLB, "language");
136 0 : get(m_pStandardCB, "standard");
137 0 : get(m_pStartFT, "startft");
138 0 : get(m_pStartED, "start");
139 0 : get(m_pEndFT, "endft");
140 0 : get(m_pEndED, "end");
141 0 : get(m_pHintFT, "hintft");
142 :
143 0 : LanguageHdl(m_pLanguageLB);
144 0 : m_pLanguageLB->SetSelectHdl(LINK(this, SvxAsianLayoutPage, LanguageHdl));
145 0 : m_pStandardCB->SetClickHdl(LINK(this, SvxAsianLayoutPage, ChangeStandardHdl));
146 0 : Link aLk(LINK(this, SvxAsianLayoutPage, ModifyHdl));
147 0 : m_pStartED->SetModifyHdl(aLk);
148 0 : m_pEndED->SetModifyHdl(aLk);
149 :
150 0 : m_pLanguageLB->SetLanguageList( LANG_LIST_FBD_CHARS, false, false );
151 0 : }
152 :
153 0 : SvxAsianLayoutPage::~SvxAsianLayoutPage()
154 : {
155 0 : delete pImpl;
156 0 : }
157 :
158 0 : SfxTabPage* SvxAsianLayoutPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
159 : {
160 0 : return new SvxAsianLayoutPage(pParent, rAttrSet);
161 : }
162 :
163 0 : bool SvxAsianLayoutPage::FillItemSet( SfxItemSet& )
164 : {
165 0 : if(m_pCharKerningRB->IsChecked() != m_pCharKerningRB->GetSavedValue())
166 : {
167 0 : pImpl->aConfig.SetKerningWesternTextOnly(m_pCharKerningRB->IsChecked());
168 0 : OUString sPunct(cIsKernAsianPunctuation);
169 0 : if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sPunct))
170 : {
171 0 : Any aVal;
172 0 : sal_Bool bVal = !m_pCharKerningRB->IsChecked();
173 0 : aVal.setValue(&bVal, ::getBooleanCppuType());
174 0 : pImpl->xPrSet->setPropertyValue(sPunct, aVal);
175 0 : }
176 : }
177 :
178 0 : if(m_pNoCompressionRB->IsChecked() != m_pNoCompressionRB->GetSavedValue() ||
179 0 : m_pPunctCompressionRB->IsChecked() != m_pPunctCompressionRB->GetSavedValue())
180 : {
181 0 : sal_Int16 nSet = m_pNoCompressionRB->IsChecked() ? 0 :
182 0 : m_pPunctCompressionRB->IsChecked() ? 1 : 2;
183 0 : pImpl->aConfig.SetCharDistanceCompression(nSet);
184 0 : OUString sCompress(cCharacterCompressionType);
185 0 : if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sCompress))
186 : {
187 0 : Any aVal;
188 0 : aVal <<= nSet;
189 0 : pImpl->xPrSet->setPropertyValue(sCompress, aVal);
190 0 : }
191 : }
192 0 : pImpl->aConfig.Commit();
193 0 : if(pImpl->xForbidden.is())
194 : {
195 : try
196 : {
197 0 : SvxForbiddenCharacterMap_Impl::iterator itElem;
198 0 : for( itElem = pImpl->aChangedLanguagesMap.begin();
199 0 : itElem != pImpl->aChangedLanguagesMap.end(); ++itElem )
200 : {
201 0 : Locale aLocale( LanguageTag::convertToLocale( itElem->first ));
202 0 : if(itElem->second->bRemoved)
203 0 : pImpl->xForbidden->removeForbiddenCharacters( aLocale );
204 0 : else if(itElem->second->pCharacters)
205 0 : pImpl->xForbidden->setForbiddenCharacters( aLocale, *( itElem->second->pCharacters ) );
206 0 : }
207 : }
208 0 : catch (const Exception&)
209 : {
210 : OSL_FAIL("exception in XForbiddenCharacters");
211 : }
212 : }
213 0 : eLastUsedLanguageTypeForForbiddenCharacters = m_pLanguageLB->GetSelectLanguage();
214 :
215 0 : return false;
216 : }
217 :
218 0 : void SvxAsianLayoutPage::Reset( const SfxItemSet& )
219 : {
220 0 : SfxViewFrame* pCurFrm = SfxViewFrame::Current();
221 0 : SfxObjectShell* pDocSh = pCurFrm ? pCurFrm->GetObjectShell() : 0;
222 0 : Reference< XModel > xModel;
223 0 : if(pDocSh)
224 0 : xModel = pDocSh->GetModel();
225 0 : Reference<XMultiServiceFactory> xFact(xModel, UNO_QUERY);
226 0 : if(xFact.is())
227 : {
228 0 : pImpl->xPrSet = Reference<XPropertySet>(
229 0 : xFact->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
230 : }
231 0 : if( pImpl->xPrSet.is() )
232 0 : pImpl->xPrSetInfo = pImpl->xPrSet->getPropertySetInfo();
233 0 : OUString sForbidden("ForbiddenCharacters");
234 0 : sal_Bool bKernWesternText = pImpl->aConfig.IsKerningWesternTextOnly();
235 0 : sal_Int16 nCompress = pImpl->aConfig.GetCharDistanceCompression();
236 0 : if(pImpl->xPrSetInfo.is())
237 : {
238 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sForbidden))
239 : {
240 0 : Any aForbidden = pImpl->xPrSet->getPropertyValue(sForbidden);
241 0 : aForbidden >>= pImpl->xForbidden;
242 : }
243 0 : OUString sCompress(cCharacterCompressionType);
244 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sCompress))
245 : {
246 0 : Any aVal = pImpl->xPrSet->getPropertyValue(sCompress);
247 0 : aVal >>= nCompress;
248 : }
249 0 : OUString sPunct(cIsKernAsianPunctuation);
250 0 : if(pImpl->xPrSetInfo->hasPropertyByName(sPunct))
251 : {
252 0 : Any aVal = pImpl->xPrSet->getPropertyValue(sPunct);
253 0 : bKernWesternText = !*(sal_Bool*)aVal.getValue();
254 0 : }
255 : }
256 : else
257 : {
258 0 : m_pLanguageFT->Enable(false);
259 0 : m_pLanguageLB->Enable(false);
260 0 : m_pStandardCB->Enable(false);
261 0 : m_pStartFT->Enable(false);
262 0 : m_pStartED->Enable(false);
263 0 : m_pEndFT->Enable(false);
264 0 : m_pEndED->Enable(false);
265 0 : m_pHintFT->Enable(false);
266 : }
267 0 : if(bKernWesternText)
268 0 : m_pCharKerningRB->Check(true);
269 : else
270 0 : m_pCharPunctKerningRB->Check(true);
271 0 : switch(nCompress)
272 : {
273 0 : case 0 : m_pNoCompressionRB->Check(); break;
274 0 : case 1 : m_pPunctCompressionRB->Check(); break;
275 0 : default: m_pPunctKanaCompressionRB->Check();
276 : }
277 0 : m_pCharKerningRB->SaveValue();
278 0 : m_pNoCompressionRB->SaveValue();
279 0 : m_pPunctCompressionRB->SaveValue();
280 0 : m_pPunctKanaCompressionRB->SaveValue();
281 :
282 0 : m_pLanguageLB->SelectEntryPos(0);
283 : //preselect the system language in the box - if available
284 0 : if(USHRT_MAX == eLastUsedLanguageTypeForForbiddenCharacters)
285 : {
286 : eLastUsedLanguageTypeForForbiddenCharacters =
287 0 : Application::GetSettings().GetLanguageTag().getLanguageType();
288 0 : if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters))
289 0 : eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_SIMPLIFIED;
290 0 : else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters))
291 0 : eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_TRADITIONAL;
292 : }
293 0 : m_pLanguageLB->SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters );
294 0 : LanguageHdl(m_pLanguageLB);
295 0 : }
296 :
297 0 : IMPL_LINK_NOARG(SvxAsianLayoutPage, LanguageHdl)
298 : {
299 : //set current value
300 0 : LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
301 0 : LanguageTag aLanguageTag( eSelectLanguage);
302 0 : Locale aLocale( aLanguageTag.getLocale());
303 :
304 0 : OUString sStart, sEnd;
305 : sal_Bool bAvail;
306 0 : if(pImpl->xForbidden.is())
307 : {
308 0 : bAvail = pImpl->hasForbiddenCharacters(eSelectLanguage);
309 0 : if(bAvail)
310 : {
311 0 : SvxForbiddenChars_Impl* pElement = pImpl->getForbiddenCharacters(eSelectLanguage);
312 0 : if(pElement->bRemoved || !pElement->pCharacters)
313 : {
314 0 : bAvail = sal_False;
315 : }
316 : else
317 : {
318 0 : sStart = pElement->pCharacters->beginLine;
319 0 : sEnd = pElement->pCharacters->endLine;
320 : }
321 : }
322 : else
323 : {
324 : try
325 : {
326 0 : bAvail = pImpl->xForbidden->hasForbiddenCharacters(aLocale);
327 0 : if(bAvail)
328 : {
329 0 : ForbiddenCharacters aForbidden = pImpl->xForbidden->getForbiddenCharacters( aLocale );
330 0 : sStart = aForbidden.beginLine;
331 0 : sEnd = aForbidden.endLine;
332 : }
333 : }
334 0 : catch (const Exception&)
335 : {
336 : OSL_FAIL("exception in XForbiddenCharacters");
337 : }
338 : }
339 : }
340 : else
341 : {
342 0 : bAvail = pImpl->aConfig.GetStartEndChars( aLocale, sStart, sEnd );
343 : }
344 0 : if(!bAvail)
345 : {
346 0 : LocaleDataWrapper aWrap( aLanguageTag );
347 0 : ForbiddenCharacters aForbidden = aWrap.getForbiddenCharacters();
348 0 : sStart = aForbidden.beginLine;
349 0 : sEnd = aForbidden.endLine;
350 : }
351 0 : m_pStandardCB->Check(!bAvail);
352 0 : m_pStartED->Enable(bAvail);
353 0 : m_pEndED->Enable(bAvail);
354 0 : m_pStartFT->Enable(bAvail);
355 0 : m_pEndFT->Enable(bAvail);
356 0 : m_pStartED->SetText(sStart);
357 0 : m_pEndED->SetText(sEnd);
358 :
359 0 : return 0;
360 : }
361 :
362 0 : IMPL_LINK(SvxAsianLayoutPage, ChangeStandardHdl, CheckBox*, pBox)
363 : {
364 0 : sal_Bool bCheck = pBox->IsChecked();
365 0 : m_pStartED->Enable(!bCheck);
366 0 : m_pEndED->Enable(!bCheck);
367 0 : m_pStartFT->Enable(!bCheck);
368 0 : m_pEndFT->Enable(!bCheck);
369 :
370 0 : ModifyHdl(m_pStartED);
371 0 : return 0;
372 : }
373 :
374 0 : IMPL_LINK(SvxAsianLayoutPage, ModifyHdl, Edit*, pEdit)
375 : {
376 0 : LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
377 0 : Locale aLocale( LanguageTag::convertToLocale( eSelectLanguage ));
378 0 : OUString sStart = m_pStartED->GetText();
379 0 : OUString sEnd = m_pEndED->GetText();
380 0 : sal_Bool bEnable = pEdit->IsEnabled();
381 0 : if(pImpl->xForbidden.is())
382 : {
383 : try
384 : {
385 0 : if(bEnable)
386 : {
387 0 : ForbiddenCharacters aSet;
388 0 : aSet.beginLine = sStart;
389 0 : aSet.endLine = sEnd;
390 0 : pImpl->addForbiddenCharacters(eSelectLanguage, &aSet);
391 : }
392 : else
393 0 : pImpl->addForbiddenCharacters(eSelectLanguage, 0);
394 : }
395 0 : catch (const Exception&)
396 : {
397 : OSL_FAIL("exception in XForbiddenCharacters");
398 : }
399 : }
400 0 : pImpl->aConfig.SetStartEndChars( aLocale, bEnable ? &sStart : 0, bEnable ? &sEnd : 0);
401 0 : return 0;
402 : }
403 :
404 0 : sal_uInt16* SvxAsianLayoutPage::GetRanges()
405 : {
406 : //no items are used
407 : static sal_uInt16 pAsianLayoutRanges[] = { 0 };
408 0 : return pAsianLayoutRanges;
409 0 : }
410 :
411 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|