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 <optasian.hrc>
25 #include <dialmgr.hxx>
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>
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
;
46 const sal_Char cIsKernAsianPunctuation
[] = "IsKernAsianPunctuation";
47 const sal_Char cCharacterCompressionType
[] = "CharacterCompressionType";
49 struct SvxForbiddenChars_Impl
51 ~SvxForbiddenChars_Impl();
54 ForbiddenCharacters
* pCharacters
;
57 SvxForbiddenChars_Impl::~SvxForbiddenChars_Impl()
62 typedef ::std::map
< LanguageType
, SvxForbiddenChars_Impl
* > SvxForbiddenCharacterMap_Impl
;
64 struct SvxAsianLayoutPage_Impl
66 SvxAsianConfig aConfig
;
67 SvxAsianLayoutPage_Impl() {}
69 ~SvxAsianLayoutPage_Impl();
71 Reference
< XForbiddenCharacters
> xForbidden
;
72 Reference
< XPropertySet
> xPrSet
;
73 Reference
< XPropertySetInfo
> xPrSetInfo
;
74 SvxForbiddenCharacterMap_Impl aChangedLanguagesMap
;
76 sal_Bool
hasForbiddenCharacters(LanguageType eLang
);
77 SvxForbiddenChars_Impl
* getForbiddenCharacters(LanguageType eLang
);
78 void addForbiddenCharacters(LanguageType eLang
, ForbiddenCharacters
* pForbidden
);
81 SvxAsianLayoutPage_Impl::~SvxAsianLayoutPage_Impl()
83 SvxForbiddenCharacterMap_Impl::iterator it
;
84 for( it
= aChangedLanguagesMap
.begin(); it
!= aChangedLanguagesMap
.end(); ++it
)
90 sal_Bool
SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang
)
92 return aChangedLanguagesMap
.count( eLang
);
95 SvxForbiddenChars_Impl
* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang
)
97 SvxForbiddenCharacterMap_Impl::iterator it
= aChangedLanguagesMap
.find( eLang
);
98 DBG_ASSERT( ( it
!= aChangedLanguagesMap
.end() ), "language not available");
99 if( it
!= aChangedLanguagesMap
.end() )
104 void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
105 LanguageType eLang
, ForbiddenCharacters
* pForbidden
)
107 SvxForbiddenCharacterMap_Impl::iterator itOld
= aChangedLanguagesMap
.find( eLang
);
108 if( itOld
== aChangedLanguagesMap
.end() )
110 SvxForbiddenChars_Impl
* pChar
= new SvxForbiddenChars_Impl
;
111 pChar
->bRemoved
= 0 == pForbidden
;
112 pChar
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
113 aChangedLanguagesMap
.insert( ::std::make_pair( eLang
, pChar
) );
117 itOld
->second
->bRemoved
= 0 == pForbidden
;
118 delete itOld
->second
->pCharacters
;
119 itOld
->second
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
123 static LanguageType eLastUsedLanguageTypeForForbiddenCharacters
= USHRT_MAX
;
125 SvxAsianLayoutPage::SvxAsianLayoutPage( Window
* pParent
, const SfxItemSet
& rSet
) :
126 SfxTabPage(pParent
, CUI_RES( RID_SVXPAGE_ASIAN_LAYOUT
), rSet
),
127 aKerningGB( this, CUI_RES(GB_KERNING
)),
128 aCharKerningRB( this, CUI_RES(RB_CHAR_KERNING
)),
129 aCharPunctKerningRB( this, CUI_RES(RB_CHAR_PUNCT
)),
130 aCharDistGB( this, CUI_RES(GB_CHAR_DIST
)),
131 aNoCompressionRB( this, CUI_RES(RB_NO_COMP
)),
132 aPunctCompressionRB( this, CUI_RES(RB_PUNCT_COMP
)),
133 aPunctKanaCompressionRB(this, CUI_RES(RB_PUNCT_KANA_COMP
)),
134 aStartEndGB( this, CUI_RES(GB_START_END
)),
135 aLanguageFT( this, CUI_RES(FT_LANGUAGE
)),
136 aLanguageLB( this, CUI_RES(LB_LANGUAGE
)),
137 aStandardCB( this, CUI_RES(CB_STANDARD
)),
138 aStartFT( this, CUI_RES(FT_START
)),
139 aStartED( this, CUI_RES(ED_START
)),
140 aEndFT( this, CUI_RES(FT_END
)),
141 aEndED( this, CUI_RES(ED_END
)),
142 aHintFT( this, CUI_RES(FT_HINT
)),
143 pImpl(new SvxAsianLayoutPage_Impl
)
146 LanguageHdl(&aLanguageLB
);
147 aLanguageLB
.SetSelectHdl(LINK(this, SvxAsianLayoutPage
, LanguageHdl
));
148 aStandardCB
.SetClickHdl(LINK(this, SvxAsianLayoutPage
, ChangeStandardHdl
));
149 Link
aLk(LINK(this, SvxAsianLayoutPage
, ModifyHdl
));
150 aStartED
.SetModifyHdl(aLk
);
151 aEndED
.SetModifyHdl(aLk
);
153 aLanguageLB
.SetLanguageList( LANG_LIST_FBD_CHARS
, sal_False
, sal_False
);
156 SvxAsianLayoutPage::~SvxAsianLayoutPage()
161 SfxTabPage
* SvxAsianLayoutPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
163 return new SvxAsianLayoutPage(pParent
, rAttrSet
);
166 sal_Bool
SvxAsianLayoutPage::FillItemSet( SfxItemSet
& )
168 if(aCharKerningRB
.IsChecked() != aCharKerningRB
.GetSavedValue())
170 pImpl
->aConfig
.SetKerningWesternTextOnly(aCharKerningRB
.IsChecked());
171 OUString
sPunct(cIsKernAsianPunctuation
);
172 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
175 sal_Bool bVal
= !aCharKerningRB
.IsChecked();
176 aVal
.setValue(&bVal
, ::getBooleanCppuType());
177 pImpl
->xPrSet
->setPropertyValue(sPunct
, aVal
);
181 if(aNoCompressionRB
.IsChecked() != aNoCompressionRB
.GetSavedValue() ||
182 aPunctCompressionRB
.IsChecked() != aPunctCompressionRB
.GetSavedValue())
184 sal_Int16 nSet
= aNoCompressionRB
.IsChecked() ? 0 :
185 aPunctCompressionRB
.IsChecked() ? 1 : 2;
186 pImpl
->aConfig
.SetCharDistanceCompression(nSet
);
187 OUString
sCompress(cCharacterCompressionType
);
188 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
192 pImpl
->xPrSet
->setPropertyValue(sCompress
, aVal
);
195 pImpl
->aConfig
.Commit();
196 if(pImpl
->xForbidden
.is())
200 SvxForbiddenCharacterMap_Impl::iterator itElem
;
201 for( itElem
= pImpl
->aChangedLanguagesMap
.begin();
202 itElem
!= pImpl
->aChangedLanguagesMap
.end(); ++itElem
)
204 Locale
aLocale( LanguageTag( itElem
->first
).getLocale());
205 if(itElem
->second
->bRemoved
)
206 pImpl
->xForbidden
->removeForbiddenCharacters( aLocale
);
207 else if(itElem
->second
->pCharacters
)
208 pImpl
->xForbidden
->setForbiddenCharacters( aLocale
, *( itElem
->second
->pCharacters
) );
211 catch (const Exception
&)
213 OSL_FAIL("exception in XForbiddenCharacters");
216 eLastUsedLanguageTypeForForbiddenCharacters
= aLanguageLB
.GetSelectLanguage();
221 void SvxAsianLayoutPage::Reset( const SfxItemSet
& )
223 SfxViewFrame
* pCurFrm
= SfxViewFrame::Current();
224 SfxObjectShell
* pDocSh
= pCurFrm
? pCurFrm
->GetObjectShell() : 0;
225 Reference
< XModel
> xModel
;
227 xModel
= pDocSh
->GetModel();
228 Reference
<XMultiServiceFactory
> xFact(xModel
, UNO_QUERY
);
231 pImpl
->xPrSet
= Reference
<XPropertySet
>(
232 xFact
->createInstance("com.sun.star.document.Settings"), UNO_QUERY
);
234 if( pImpl
->xPrSet
.is() )
235 pImpl
->xPrSetInfo
= pImpl
->xPrSet
->getPropertySetInfo();
236 OUString
sForbidden("ForbiddenCharacters");
237 sal_Bool bKernWesternText
= pImpl
->aConfig
.IsKerningWesternTextOnly();
238 sal_Int16 nCompress
= pImpl
->aConfig
.GetCharDistanceCompression();
239 if(pImpl
->xPrSetInfo
.is())
241 if(pImpl
->xPrSetInfo
->hasPropertyByName(sForbidden
))
243 Any aForbidden
= pImpl
->xPrSet
->getPropertyValue(sForbidden
);
244 aForbidden
>>= pImpl
->xForbidden
;
246 OUString
sCompress(cCharacterCompressionType
);
247 if(pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
249 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sCompress
);
252 OUString
sPunct(cIsKernAsianPunctuation
);
253 if(pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
255 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sPunct
);
256 bKernWesternText
= !*(sal_Bool
*)aVal
.getValue();
261 aStartEndGB
.Enable(sal_False
);
262 aLanguageFT
.Enable(sal_False
);
263 aLanguageLB
.Enable(sal_False
);
264 aStandardCB
.Enable(sal_False
);
265 aStartFT
.Enable(sal_False
);
266 aStartED
.Enable(sal_False
);
267 aEndFT
.Enable(sal_False
);
268 aEndED
.Enable(sal_False
);
269 aHintFT
.Enable(sal_False
);
272 aCharKerningRB
.Check(sal_True
);
274 aCharPunctKerningRB
.Check(sal_True
);
277 case 0 : aNoCompressionRB
.Check(); break;
278 case 1 : aPunctCompressionRB
.Check(); break;
279 default: aPunctKanaCompressionRB
.Check();
281 aCharKerningRB
.SaveValue();
282 aNoCompressionRB
.SaveValue();
283 aPunctCompressionRB
.SaveValue();
284 aPunctKanaCompressionRB
.SaveValue();
286 aLanguageLB
.SelectEntryPos(0);
287 //preselect the system language in the box - if available
288 if(USHRT_MAX
== eLastUsedLanguageTypeForForbiddenCharacters
)
290 eLastUsedLanguageTypeForForbiddenCharacters
=
291 Application::GetSettings().GetLanguageTag().getLanguageType();
292 if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters
))
293 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_SIMPLIFIED
;
294 else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters
))
295 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_TRADITIONAL
;
297 aLanguageLB
.SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters
);
298 LanguageHdl(&aLanguageLB
);
301 IMPL_LINK_NOARG(SvxAsianLayoutPage
, LanguageHdl
)
304 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
305 LanguageTag
aLanguageTag( eSelectLanguage
);
306 Locale
aLocale( aLanguageTag
.getLocale());
308 OUString sStart
, sEnd
;
310 if(pImpl
->xForbidden
.is())
312 bAvail
= pImpl
->hasForbiddenCharacters(eSelectLanguage
);
315 SvxForbiddenChars_Impl
* pElement
= pImpl
->getForbiddenCharacters(eSelectLanguage
);
316 if(pElement
->bRemoved
|| !pElement
->pCharacters
)
322 sStart
= pElement
->pCharacters
->beginLine
;
323 sEnd
= pElement
->pCharacters
->endLine
;
330 bAvail
= pImpl
->xForbidden
->hasForbiddenCharacters(aLocale
);
333 ForbiddenCharacters aForbidden
= pImpl
->xForbidden
->getForbiddenCharacters( aLocale
);
334 sStart
= aForbidden
.beginLine
;
335 sEnd
= aForbidden
.endLine
;
338 catch (const Exception
&)
340 OSL_FAIL("exception in XForbiddenCharacters");
346 bAvail
= pImpl
->aConfig
.GetStartEndChars( aLocale
, sStart
, sEnd
);
350 LocaleDataWrapper
aWrap( aLanguageTag
);
351 ForbiddenCharacters aForbidden
= aWrap
.getForbiddenCharacters();
352 sStart
= aForbidden
.beginLine
;
353 sEnd
= aForbidden
.endLine
;
355 aStandardCB
.Check(!bAvail
);
356 aStartED
.Enable(bAvail
);
357 aEndED
.Enable(bAvail
);
358 aStartFT
.Enable(bAvail
);
359 aEndFT
.Enable(bAvail
);
360 aStartED
.SetText(sStart
);
361 aEndED
.SetText(sEnd
);
366 IMPL_LINK(SvxAsianLayoutPage
, ChangeStandardHdl
, CheckBox
*, pBox
)
368 sal_Bool bCheck
= pBox
->IsChecked();
369 aStartED
.Enable(!bCheck
);
370 aEndED
.Enable(!bCheck
);
371 aStartFT
.Enable(!bCheck
);
372 aEndFT
.Enable(!bCheck
);
374 ModifyHdl(&aStartED
);
378 IMPL_LINK(SvxAsianLayoutPage
, ModifyHdl
, Edit
*, pEdit
)
380 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
381 Locale
aLocale( LanguageTag( eSelectLanguage
).getLocale());
382 OUString sStart
= aStartED
.GetText();
383 OUString sEnd
= aEndED
.GetText();
384 sal_Bool bEnable
= pEdit
->IsEnabled();
385 if(pImpl
->xForbidden
.is())
391 ForbiddenCharacters aSet
;
392 aSet
.beginLine
= sStart
;
394 pImpl
->addForbiddenCharacters(eSelectLanguage
, &aSet
);
397 pImpl
->addForbiddenCharacters(eSelectLanguage
, 0);
399 catch (const Exception
&)
401 OSL_FAIL("exception in XForbiddenCharacters");
404 pImpl
->aConfig
.SetStartEndChars( aLocale
, bEnable
? &sStart
: 0, bEnable
? &sEnd
: 0);
408 sal_uInt16
* SvxAsianLayoutPage::GetRanges()
411 static sal_uInt16 pAsianLayoutRanges
[] = { 0 };
412 return pAsianLayoutRanges
;
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */