1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include <optasian.hxx>
32 #include <editeng/langitem.hxx>
33 #include <editeng/unolingu.hxx>
34 #include <optasian.hrc>
35 #include <dialmgr.hxx>
37 #include <tools/table.hxx>
38 #include <tools/shl.hxx>
39 #include <svl/asiancfg.hxx>
40 #include <com/sun/star/lang/Locale.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <sfx2/viewfrm.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <vcl/svapp.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <unotools/localedatawrapper.hxx>
50 using namespace com::sun::star::uno
;
51 using namespace com::sun::star::lang
;
52 using namespace com::sun::star::i18n
;
53 using namespace com::sun::star::frame
;
54 using namespace com::sun::star::beans
;
57 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
59 const sal_Char cIsKernAsianPunctuation
[] = "IsKernAsianPunctuation";
60 const sal_Char cCharacterCompressionType
[] = "CharacterCompressionType";
62 struct SvxForbiddenChars_Impl
65 ForbiddenCharacters
* pCharacters
;
68 DECLARE_TABLE( _SvxForbiddenCharacterTable_Impl
, SvxForbiddenChars_Impl
* )
70 class SvxForbiddenCharacterTable_Impl
: public _SvxForbiddenCharacterTable_Impl
73 SvxForbiddenCharacterTable_Impl()
74 : _SvxForbiddenCharacterTable_Impl( 4, 4 )
76 ~SvxForbiddenCharacterTable_Impl();
79 struct SvxAsianLayoutPage_Impl
81 SvxAsianConfig aConfig
;
82 SvxAsianLayoutPage_Impl() :
85 Reference
< XForbiddenCharacters
> xForbidden
;
86 Reference
< XPropertySet
> xPrSet
;
87 Reference
< XPropertySetInfo
> xPrSetInfo
;
88 SvxForbiddenCharacterTable_Impl aChangedLanguagesTbl
;
90 sal_Bool
hasForbiddenCharacters(LanguageType eLang
);
91 SvxForbiddenChars_Impl
* getForbiddenCharacters(LanguageType eLang
);
92 void addForbiddenCharacters(LanguageType eLang
, ForbiddenCharacters
* pForbidden
);
94 /* -----------------------------24.01.01 14:50--------------------------------
96 ---------------------------------------------------------------------------*/
97 SvxForbiddenCharacterTable_Impl::~SvxForbiddenCharacterTable_Impl()
99 for( SvxForbiddenChars_Impl
* pDel
= First(); pDel
; pDel
= Next() )
101 delete pDel
->pCharacters
;
105 /* -----------------------------24.01.01 14:50--------------------------------
107 ---------------------------------------------------------------------------*/
108 sal_Bool
SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang
)
110 return 0 != aChangedLanguagesTbl
.Get(eLang
);
112 /* -----------------------------24.01.01 14:50--------------------------------
114 ---------------------------------------------------------------------------*/
115 SvxForbiddenChars_Impl
* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang
)
117 SvxForbiddenChars_Impl
* pImp
= aChangedLanguagesTbl
.Get(eLang
);
118 DBG_ASSERT(pImp
, "language not available");
123 /* -----------------------------24.01.01 14:50--------------------------------
125 ---------------------------------------------------------------------------*/
126 void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
127 LanguageType eLang
, ForbiddenCharacters
* pForbidden
)
129 SvxForbiddenChars_Impl
* pOld
= aChangedLanguagesTbl
.Get(eLang
);
132 pOld
= new SvxForbiddenChars_Impl
;
133 pOld
->bRemoved
= 0 == pForbidden
;
134 pOld
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
135 aChangedLanguagesTbl
.Insert( eLang
, pOld
);
139 pOld
->bRemoved
= 0 == pForbidden
;
140 delete pOld
->pCharacters
;
141 pOld
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
145 /*-- 09.01.01 13:29:02---------------------------------------------------
147 -----------------------------------------------------------------------*/
148 static LanguageType eLastUsedLanguageTypeForForbiddenCharacters
= USHRT_MAX
;
150 SvxAsianLayoutPage::SvxAsianLayoutPage( Window
* pParent
, const SfxItemSet
& rSet
) :
151 SfxTabPage(pParent
, CUI_RES( RID_SVXPAGE_ASIAN_LAYOUT
), rSet
),
152 aKerningGB( this, CUI_RES(GB_KERNING
)),
153 aCharKerningRB( this, CUI_RES(RB_CHAR_KERNING
)),
154 aCharPunctKerningRB( this, CUI_RES(RB_CHAR_PUNCT
)),
155 aCharDistGB( this, CUI_RES(GB_CHAR_DIST
)),
156 aNoCompressionRB( this, CUI_RES(RB_NO_COMP
)),
157 aPunctCompressionRB( this, CUI_RES(RB_PUNCT_COMP
)),
158 aPunctKanaCompressionRB(this, CUI_RES(RB_PUNCT_KANA_COMP
)),
159 aStartEndGB( this, CUI_RES(GB_START_END
)),
160 aLanguageFT( this, CUI_RES(FT_LANGUAGE
)),
161 aLanguageLB( this, CUI_RES(LB_LANGUAGE
)),
162 aStandardCB( this, CUI_RES(CB_STANDARD
)),
163 aStartFT( this, CUI_RES(FT_START
)),
164 aStartED( this, CUI_RES(ED_START
)),
165 aEndFT( this, CUI_RES(FT_END
)),
166 aEndED( this, CUI_RES(ED_END
)),
167 aHintFT( this, CUI_RES(FT_HINT
)),
168 pImpl(new SvxAsianLayoutPage_Impl
)
171 LanguageHdl(&aLanguageLB
);
172 aLanguageLB
.SetSelectHdl(LINK(this, SvxAsianLayoutPage
, LanguageHdl
));
173 aStandardCB
.SetClickHdl(LINK(this, SvxAsianLayoutPage
, ChangeStandardHdl
));
174 Link
aLk(LINK(this, SvxAsianLayoutPage
, ModifyHdl
));
175 aStartED
.SetModifyHdl(aLk
);
176 aEndED
.SetModifyHdl(aLk
);
178 aLanguageLB
.SetLanguageList( LANG_LIST_FBD_CHARS
, sal_False
, sal_False
);
180 /*-- 09.01.01 13:29:02---------------------------------------------------
182 -----------------------------------------------------------------------*/
183 SvxAsianLayoutPage::~SvxAsianLayoutPage()
187 /*-- 09.01.01 13:29:02---------------------------------------------------
189 -----------------------------------------------------------------------*/
190 SfxTabPage
* SvxAsianLayoutPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
192 return new SvxAsianLayoutPage(pParent
, rAttrSet
);
194 /*-- 09.01.01 13:29:03---------------------------------------------------
196 -----------------------------------------------------------------------*/
197 sal_Bool
SvxAsianLayoutPage::FillItemSet( SfxItemSet
& )
199 if(aCharKerningRB
.IsChecked() != aCharKerningRB
.GetSavedValue())
201 pImpl
->aConfig
.SetKerningWesternTextOnly(aCharKerningRB
.IsChecked());
202 OUString
sPunct(C2U(cIsKernAsianPunctuation
));
203 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
206 sal_Bool bVal
= !aCharKerningRB
.IsChecked();
207 aVal
.setValue(&bVal
, ::getBooleanCppuType());
208 pImpl
->xPrSet
->setPropertyValue(sPunct
, aVal
);
212 if(aNoCompressionRB
.IsChecked() != aNoCompressionRB
.GetSavedValue() ||
213 aPunctCompressionRB
.IsChecked() != aPunctCompressionRB
.GetSavedValue())
215 sal_Int16 nSet
= aNoCompressionRB
.IsChecked() ? 0 :
216 aPunctCompressionRB
.IsChecked() ? 1 : 2;
217 pImpl
->aConfig
.SetCharDistanceCompression(nSet
);
218 OUString
sCompress(C2U(cCharacterCompressionType
));
219 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
223 pImpl
->xPrSet
->setPropertyValue(sCompress
, aVal
);
226 if(pImpl
->aConfig
.IsModified())
227 pImpl
->aConfig
.Commit();
228 if(pImpl
->xForbidden
.is())
232 for( SvxForbiddenChars_Impl
* pElem
= pImpl
->aChangedLanguagesTbl
.First();
233 pElem
; pElem
= pImpl
->aChangedLanguagesTbl
.Next() )
235 sal_uLong nLang
= pImpl
->aChangedLanguagesTbl
.GetKey( pElem
);
237 SvxLanguageToLocale(aLocale
, (sal_uInt16
)nLang
);
239 pImpl
->xForbidden
->removeForbiddenCharacters( aLocale
);
240 else if(pElem
->pCharacters
)
241 pImpl
->xForbidden
->setForbiddenCharacters( aLocale
, *pElem
->pCharacters
);
246 DBG_ERROR("exception in XForbiddenCharacters");
249 eLastUsedLanguageTypeForForbiddenCharacters
= aLanguageLB
.GetSelectLanguage();
253 /*-- 09.01.01 13:29:03---------------------------------------------------
255 -----------------------------------------------------------------------*/
256 void SvxAsianLayoutPage::Reset( const SfxItemSet
& )
258 SfxViewFrame
* pCurFrm
= SfxViewFrame::Current();
259 SfxObjectShell
* pDocSh
= pCurFrm
? pCurFrm
->GetObjectShell() : 0;
260 Reference
< XModel
> xModel
;
262 xModel
= pDocSh
->GetModel();
263 Reference
<XMultiServiceFactory
> xFact(xModel
, UNO_QUERY
);
266 pImpl
->xPrSet
= Reference
<XPropertySet
>(
267 xFact
->createInstance(C2U("com.sun.star.document.Settings")), UNO_QUERY
);
269 if( pImpl
->xPrSet
.is() )
270 pImpl
->xPrSetInfo
= pImpl
->xPrSet
->getPropertySetInfo();
271 OUString
sForbidden(C2U("ForbiddenCharacters"));
272 sal_Bool bKernWesternText
= pImpl
->aConfig
.IsKerningWesternTextOnly();
273 sal_Int16 nCompress
= pImpl
->aConfig
.GetCharDistanceCompression();
274 if(pImpl
->xPrSetInfo
.is())
276 if(pImpl
->xPrSetInfo
->hasPropertyByName(sForbidden
))
278 Any aForbidden
= pImpl
->xPrSet
->getPropertyValue(sForbidden
);
279 aForbidden
>>= pImpl
->xForbidden
;
281 OUString
sCompress(C2U(cCharacterCompressionType
));
282 if(pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
284 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sCompress
);
287 OUString
sPunct(C2U(cIsKernAsianPunctuation
));
288 if(pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
290 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sPunct
);
291 bKernWesternText
= !*(sal_Bool
*)aVal
.getValue();
296 aStartEndGB
.Enable(sal_False
);
297 aLanguageFT
.Enable(sal_False
);
298 aLanguageLB
.Enable(sal_False
);
299 aStandardCB
.Enable(sal_False
);
300 aStartFT
.Enable(sal_False
);
301 aStartED
.Enable(sal_False
);
302 aEndFT
.Enable(sal_False
);
303 aEndED
.Enable(sal_False
);
304 aHintFT
.Enable(sal_False
);
307 aCharKerningRB
.Check(sal_True
);
309 aCharPunctKerningRB
.Check(sal_True
);
312 case 0 : aNoCompressionRB
.Check(); break;
313 case 1 : aPunctCompressionRB
.Check(); break;
314 default: aPunctKanaCompressionRB
.Check();
316 aCharKerningRB
.SaveValue();
317 aNoCompressionRB
.SaveValue();
318 aPunctCompressionRB
.SaveValue();
319 aPunctKanaCompressionRB
.SaveValue();
321 aLanguageLB
.SelectEntryPos(0);
322 //preselect the system language in the box - if available
323 if(USHRT_MAX
== eLastUsedLanguageTypeForForbiddenCharacters
)
325 eLastUsedLanguageTypeForForbiddenCharacters
= SvxLocaleToLanguage(
326 Application::GetSettings().GetLocale() );
327 switch(eLastUsedLanguageTypeForForbiddenCharacters
)
329 case LANGUAGE_CHINESE
:
330 case LANGUAGE_CHINESE_SINGAPORE
:
331 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_SIMPLIFIED
;
333 case LANGUAGE_CHINESE_HONGKONG
:
334 case LANGUAGE_CHINESE_MACAU
:
335 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_TRADITIONAL
;
339 aLanguageLB
.SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters
);
340 LanguageHdl(&aLanguageLB
);
342 /* -----------------------------17.01.01 11:02--------------------------------
344 ---------------------------------------------------------------------------*/
345 IMPL_LINK(SvxAsianLayoutPage
, LanguageHdl
, SvxLanguageBox
*, EMPTYARG
)
349 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
350 SvxLanguageToLocale(aLocale
, eSelectLanguage
);
352 OUString sStart
, sEnd
;
354 if(pImpl
->xForbidden
.is())
356 bAvail
= pImpl
->hasForbiddenCharacters(eSelectLanguage
);
359 SvxForbiddenChars_Impl
* pElement
= pImpl
->getForbiddenCharacters(eSelectLanguage
);
360 if(pElement
->bRemoved
|| !pElement
->pCharacters
)
366 sStart
= pElement
->pCharacters
->beginLine
;
367 sEnd
= pElement
->pCharacters
->endLine
;
374 bAvail
= pImpl
->xForbidden
->hasForbiddenCharacters(aLocale
);
377 ForbiddenCharacters aForbidden
= pImpl
->xForbidden
->getForbiddenCharacters( aLocale
);
378 sStart
= aForbidden
.beginLine
;
379 sEnd
= aForbidden
.endLine
;
384 DBG_ERROR("exception in XForbiddenCharacters");
390 bAvail
= pImpl
->aConfig
.GetStartEndChars( aLocale
, sStart
, sEnd
);
394 Reference
< XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
395 LocaleDataWrapper
aWrap( xMSF
, aLocale
);
396 ForbiddenCharacters aForbidden
= aWrap
.getForbiddenCharacters();
397 sStart
= aForbidden
.beginLine
;
398 sEnd
= aForbidden
.endLine
;
400 aStandardCB
.Check(!bAvail
);
401 aStartED
.Enable(bAvail
);
402 aEndED
.Enable(bAvail
);
403 aStartFT
.Enable(bAvail
);
404 aEndFT
.Enable(bAvail
);
405 aStartED
.SetText(sStart
);
406 aEndED
.SetText(sEnd
);
410 /* -----------------------------17.01.01 11:02--------------------------------
412 ---------------------------------------------------------------------------*/
413 IMPL_LINK(SvxAsianLayoutPage
, ChangeStandardHdl
, CheckBox
*, pBox
)
415 sal_Bool bCheck
= pBox
->IsChecked();
416 aStartED
.Enable(!bCheck
);
417 aEndED
.Enable(!bCheck
);
418 aStartFT
.Enable(!bCheck
);
419 aEndFT
.Enable(!bCheck
);
421 ModifyHdl(&aStartED
);
424 /* -----------------------------17.01.01 12:26--------------------------------
426 ---------------------------------------------------------------------------*/
427 IMPL_LINK(SvxAsianLayoutPage
, ModifyHdl
, Edit
*, pEdit
)
430 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
431 SvxLanguageToLocale(aLocale
, eSelectLanguage
);
432 OUString sStart
= aStartED
.GetText();
433 OUString sEnd
= aEndED
.GetText();
434 sal_Bool bEnable
= pEdit
->IsEnabled();
435 if(pImpl
->xForbidden
.is())
441 ForbiddenCharacters aSet
;
442 aSet
.beginLine
= sStart
;
444 // pImpl->xForbidden->setForbiddenCharacters( aLocale, aSet );
445 pImpl
->addForbiddenCharacters(eSelectLanguage
, &aSet
);
448 pImpl
->addForbiddenCharacters(eSelectLanguage
, 0);
449 // pImpl->xForbidden->removeForbiddenCharacters( aLocale );
453 DBG_ERROR("exception in XForbiddenCharacters");
456 pImpl
->aConfig
.SetStartEndChars( aLocale
, bEnable
? &sStart
: 0, bEnable
? &sEnd
: 0);
459 /*-- 07.09.2007 12:05:09---------------------------------------------------
461 -----------------------------------------------------------------------*/
462 sal_uInt16
* SvxAsianLayoutPage::GetRanges()
465 static sal_uInt16 pAsianLayoutRanges
[] = { 0 };
466 return pAsianLayoutRanges
;