1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <optasian.hxx>
22 #include <editeng/langitem.hxx>
23 #include <editeng/unolingu.hxx>
24 #include <dialmgr.hxx>
26 #include <i18nlangtag/mslangid.hxx>
27 #include <svl/asiancfg.hxx>
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/objsh.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <unotools/localedatawrapper.hxx>
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::lang
;
41 using namespace com::sun::star::i18n
;
42 using namespace com::sun::star::frame
;
43 using namespace com::sun::star::beans
;
45 const sal_Char cIsKernAsianPunctuation
[] = "IsKernAsianPunctuation";
46 const sal_Char cCharacterCompressionType
[] = "CharacterCompressionType";
48 struct SvxForbiddenChars_Impl
50 ~SvxForbiddenChars_Impl();
53 ForbiddenCharacters
* pCharacters
;
56 SvxForbiddenChars_Impl::~SvxForbiddenChars_Impl()
61 typedef ::std::map
< LanguageType
, SvxForbiddenChars_Impl
* > SvxForbiddenCharacterMap_Impl
;
63 struct SvxAsianLayoutPage_Impl
65 SvxAsianConfig aConfig
;
66 SvxAsianLayoutPage_Impl() {}
68 ~SvxAsianLayoutPage_Impl();
70 Reference
< XForbiddenCharacters
> xForbidden
;
71 Reference
< XPropertySet
> xPrSet
;
72 Reference
< XPropertySetInfo
> xPrSetInfo
;
73 SvxForbiddenCharacterMap_Impl aChangedLanguagesMap
;
75 bool hasForbiddenCharacters(LanguageType eLang
);
76 SvxForbiddenChars_Impl
* getForbiddenCharacters(LanguageType eLang
);
77 void addForbiddenCharacters(LanguageType eLang
, ForbiddenCharacters
* pForbidden
);
80 SvxAsianLayoutPage_Impl::~SvxAsianLayoutPage_Impl()
82 SvxForbiddenCharacterMap_Impl::iterator it
;
83 for( it
= aChangedLanguagesMap
.begin(); it
!= aChangedLanguagesMap
.end(); ++it
)
89 bool SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang
)
91 return aChangedLanguagesMap
.count( eLang
);
94 SvxForbiddenChars_Impl
* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang
)
96 SvxForbiddenCharacterMap_Impl::iterator it
= aChangedLanguagesMap
.find( eLang
);
97 DBG_ASSERT( ( it
!= aChangedLanguagesMap
.end() ), "language not available");
98 if( it
!= aChangedLanguagesMap
.end() )
103 void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
104 LanguageType eLang
, ForbiddenCharacters
* pForbidden
)
106 SvxForbiddenCharacterMap_Impl::iterator itOld
= aChangedLanguagesMap
.find( eLang
);
107 if( itOld
== aChangedLanguagesMap
.end() )
109 SvxForbiddenChars_Impl
* pChar
= new SvxForbiddenChars_Impl
;
110 pChar
->bRemoved
= 0 == pForbidden
;
111 pChar
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
112 aChangedLanguagesMap
.insert( ::std::make_pair( eLang
, pChar
) );
116 itOld
->second
->bRemoved
= 0 == pForbidden
;
117 delete itOld
->second
->pCharacters
;
118 itOld
->second
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
122 static LanguageType eLastUsedLanguageTypeForForbiddenCharacters
= USHRT_MAX
;
124 SvxAsianLayoutPage::SvxAsianLayoutPage( vcl::Window
* pParent
, const SfxItemSet
& rSet
) :
125 SfxTabPage(pParent
, "OptAsianPage", "cui/ui/optasianpage.ui", &rSet
),
126 pImpl(new SvxAsianLayoutPage_Impl
)
128 get(m_pCharKerningRB
, "charkerning");
129 get(m_pCharPunctKerningRB
, "charpunctkerning");
130 get(m_pNoCompressionRB
, "nocompression");
131 get(m_pPunctCompressionRB
, "punctcompression");
132 get(m_pPunctKanaCompressionRB
, "punctkanacompression");
133 get(m_pLanguageFT
, "languageft");
134 get(m_pLanguageLB
, "language");
135 get(m_pStandardCB
, "standard");
136 get(m_pStartFT
, "startft");
137 get(m_pStartED
, "start");
138 get(m_pEndFT
, "endft");
139 get(m_pEndED
, "end");
140 get(m_pHintFT
, "hintft");
142 LanguageHdl(m_pLanguageLB
);
143 m_pLanguageLB
->SetSelectHdl(LINK(this, SvxAsianLayoutPage
, LanguageHdl
));
144 m_pStandardCB
->SetClickHdl(LINK(this, SvxAsianLayoutPage
, ChangeStandardHdl
));
145 Link
<> aLk(LINK(this, SvxAsianLayoutPage
, ModifyHdl
));
146 m_pStartED
->SetModifyHdl(aLk
);
147 m_pEndED
->SetModifyHdl(aLk
);
149 m_pLanguageLB
->SetLanguageList( SvxLanguageListFlags::FBD_CHARS
, false, false );
152 SvxAsianLayoutPage::~SvxAsianLayoutPage()
157 void SvxAsianLayoutPage::dispose()
161 m_pCharKerningRB
.clear();
162 m_pCharPunctKerningRB
.clear();
163 m_pNoCompressionRB
.clear();
164 m_pPunctCompressionRB
.clear();
165 m_pPunctKanaCompressionRB
.clear();
166 m_pLanguageFT
.clear();
167 m_pLanguageLB
.clear();
168 m_pStandardCB
.clear();
174 SfxTabPage::dispose();
177 VclPtr
<SfxTabPage
> SvxAsianLayoutPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
179 return VclPtr
<SvxAsianLayoutPage
>::Create(pParent
, *rAttrSet
);
182 bool SvxAsianLayoutPage::FillItemSet( SfxItemSet
* )
184 if(m_pCharKerningRB
->IsValueChangedFromSaved())
186 pImpl
->aConfig
.SetKerningWesternTextOnly(m_pCharKerningRB
->IsChecked());
187 OUString
sPunct(cIsKernAsianPunctuation
);
188 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
191 sal_Bool bVal
= !m_pCharKerningRB
->IsChecked();
192 aVal
.setValue(&bVal
, cppu::UnoType
<bool>::get());
193 pImpl
->xPrSet
->setPropertyValue(sPunct
, aVal
);
197 if(m_pNoCompressionRB
->IsValueChangedFromSaved() ||
198 m_pPunctCompressionRB
->IsValueChangedFromSaved())
200 sal_Int16 nSet
= m_pNoCompressionRB
->IsChecked() ? 0 :
201 m_pPunctCompressionRB
->IsChecked() ? 1 : 2;
202 pImpl
->aConfig
.SetCharDistanceCompression(nSet
);
203 OUString
sCompress(cCharacterCompressionType
);
204 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
208 pImpl
->xPrSet
->setPropertyValue(sCompress
, aVal
);
211 pImpl
->aConfig
.Commit();
212 if(pImpl
->xForbidden
.is())
216 SvxForbiddenCharacterMap_Impl::iterator itElem
;
217 for( itElem
= pImpl
->aChangedLanguagesMap
.begin();
218 itElem
!= pImpl
->aChangedLanguagesMap
.end(); ++itElem
)
220 Locale
aLocale( LanguageTag::convertToLocale( itElem
->first
));
221 if(itElem
->second
->bRemoved
)
222 pImpl
->xForbidden
->removeForbiddenCharacters( aLocale
);
223 else if(itElem
->second
->pCharacters
)
224 pImpl
->xForbidden
->setForbiddenCharacters( aLocale
, *( itElem
->second
->pCharacters
) );
227 catch (const Exception
&)
229 OSL_FAIL("exception in XForbiddenCharacters");
232 eLastUsedLanguageTypeForForbiddenCharacters
= m_pLanguageLB
->GetSelectLanguage();
237 void SvxAsianLayoutPage::Reset( const SfxItemSet
* )
239 SfxViewFrame
* pCurFrm
= SfxViewFrame::Current();
240 SfxObjectShell
* pDocSh
= pCurFrm
? pCurFrm
->GetObjectShell() : 0;
241 Reference
< XModel
> xModel
;
243 xModel
= pDocSh
->GetModel();
244 Reference
<XMultiServiceFactory
> xFact(xModel
, UNO_QUERY
);
247 pImpl
->xPrSet
= Reference
<XPropertySet
>(
248 xFact
->createInstance("com.sun.star.document.Settings"), UNO_QUERY
);
250 if( pImpl
->xPrSet
.is() )
251 pImpl
->xPrSetInfo
= pImpl
->xPrSet
->getPropertySetInfo();
252 OUString
sForbidden("ForbiddenCharacters");
253 bool bKernWesternText
= pImpl
->aConfig
.IsKerningWesternTextOnly();
254 sal_Int16 nCompress
= pImpl
->aConfig
.GetCharDistanceCompression();
255 if(pImpl
->xPrSetInfo
.is())
257 if(pImpl
->xPrSetInfo
->hasPropertyByName(sForbidden
))
259 Any aForbidden
= pImpl
->xPrSet
->getPropertyValue(sForbidden
);
260 aForbidden
>>= pImpl
->xForbidden
;
262 OUString
sCompress(cCharacterCompressionType
);
263 if(pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
265 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sCompress
);
268 OUString
sPunct(cIsKernAsianPunctuation
);
269 if(pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
271 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sPunct
);
272 bKernWesternText
= !*static_cast<sal_Bool
const *>(aVal
.getValue());
277 m_pLanguageFT
->Enable(false);
278 m_pLanguageLB
->Enable(false);
279 m_pStandardCB
->Enable(false);
280 m_pStartFT
->Enable(false);
281 m_pStartED
->Enable(false);
282 m_pEndFT
->Enable(false);
283 m_pEndED
->Enable(false);
284 m_pHintFT
->Enable(false);
287 m_pCharKerningRB
->Check(true);
289 m_pCharPunctKerningRB
->Check(true);
292 case 0 : m_pNoCompressionRB
->Check(); break;
293 case 1 : m_pPunctCompressionRB
->Check(); break;
294 default: m_pPunctKanaCompressionRB
->Check();
296 m_pCharKerningRB
->SaveValue();
297 m_pNoCompressionRB
->SaveValue();
298 m_pPunctCompressionRB
->SaveValue();
299 m_pPunctKanaCompressionRB
->SaveValue();
301 m_pLanguageLB
->SelectEntryPos(0);
302 //preselect the system language in the box - if available
303 if(USHRT_MAX
== eLastUsedLanguageTypeForForbiddenCharacters
)
305 eLastUsedLanguageTypeForForbiddenCharacters
=
306 Application::GetSettings().GetLanguageTag().getLanguageType();
307 if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters
))
308 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_SIMPLIFIED
;
309 else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters
))
310 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_TRADITIONAL
;
312 m_pLanguageLB
->SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters
);
313 LanguageHdl(m_pLanguageLB
);
316 IMPL_LINK_NOARG(SvxAsianLayoutPage
, LanguageHdl
)
319 LanguageType eSelectLanguage
= m_pLanguageLB
->GetSelectLanguage();
320 LanguageTag
aLanguageTag( eSelectLanguage
);
321 Locale
aLocale( aLanguageTag
.getLocale());
323 OUString sStart
, sEnd
;
325 if(pImpl
->xForbidden
.is())
327 bAvail
= pImpl
->hasForbiddenCharacters(eSelectLanguage
);
330 SvxForbiddenChars_Impl
* pElement
= pImpl
->getForbiddenCharacters(eSelectLanguage
);
331 if(pElement
->bRemoved
|| !pElement
->pCharacters
)
337 sStart
= pElement
->pCharacters
->beginLine
;
338 sEnd
= pElement
->pCharacters
->endLine
;
345 bAvail
= pImpl
->xForbidden
->hasForbiddenCharacters(aLocale
);
348 ForbiddenCharacters aForbidden
= pImpl
->xForbidden
->getForbiddenCharacters( aLocale
);
349 sStart
= aForbidden
.beginLine
;
350 sEnd
= aForbidden
.endLine
;
353 catch (const Exception
&)
355 OSL_FAIL("exception in XForbiddenCharacters");
361 bAvail
= pImpl
->aConfig
.GetStartEndChars( aLocale
, sStart
, sEnd
);
365 LocaleDataWrapper
aWrap( aLanguageTag
);
366 ForbiddenCharacters aForbidden
= aWrap
.getForbiddenCharacters();
367 sStart
= aForbidden
.beginLine
;
368 sEnd
= aForbidden
.endLine
;
370 m_pStandardCB
->Check(!bAvail
);
371 m_pStartED
->Enable(bAvail
);
372 m_pEndED
->Enable(bAvail
);
373 m_pStartFT
->Enable(bAvail
);
374 m_pEndFT
->Enable(bAvail
);
375 m_pStartED
->SetText(sStart
);
376 m_pEndED
->SetText(sEnd
);
381 IMPL_LINK(SvxAsianLayoutPage
, ChangeStandardHdl
, CheckBox
*, pBox
)
383 bool bCheck
= pBox
->IsChecked();
384 m_pStartED
->Enable(!bCheck
);
385 m_pEndED
->Enable(!bCheck
);
386 m_pStartFT
->Enable(!bCheck
);
387 m_pEndFT
->Enable(!bCheck
);
389 ModifyHdl(m_pStartED
);
393 IMPL_LINK(SvxAsianLayoutPage
, ModifyHdl
, Edit
*, pEdit
)
395 LanguageType eSelectLanguage
= m_pLanguageLB
->GetSelectLanguage();
396 Locale
aLocale( LanguageTag::convertToLocale( eSelectLanguage
));
397 OUString sStart
= m_pStartED
->GetText();
398 OUString sEnd
= m_pEndED
->GetText();
399 bool bEnable
= pEdit
->IsEnabled();
400 if(pImpl
->xForbidden
.is())
406 ForbiddenCharacters aSet
;
407 aSet
.beginLine
= sStart
;
409 pImpl
->addForbiddenCharacters(eSelectLanguage
, &aSet
);
412 pImpl
->addForbiddenCharacters(eSelectLanguage
, 0);
414 catch (const Exception
&)
416 OSL_FAIL("exception in XForbiddenCharacters");
419 pImpl
->aConfig
.SetStartEndChars( aLocale
, bEnable
? &sStart
: 0, bEnable
? &sEnd
: 0);
423 const sal_uInt16
* SvxAsianLayoutPage::GetRanges()
426 static const sal_uInt16 pAsianLayoutRanges
[] = { 0 };
427 return pAsianLayoutRanges
;
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */