1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optasian.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <optasian.hxx>
38 #include <svx/langitem.hxx>
39 #include <unolingu.hxx>
40 #include <optasian.hrc>
41 #include <svx/dialmgr.hxx>
42 #include <svx/dialogs.hrc>
43 #ifndef _TABLE_HXX //autogen
44 #include <tools/table.hxx>
46 #include <tools/shl.hxx>
47 #include <asiancfg.hxx>
48 #include <com/sun/star/lang/Locale.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/objsh.hxx>
54 #include <vcl/svapp.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <unotools/localedatawrapper.hxx>
58 using namespace com::sun::star::uno
;
59 using namespace com::sun::star::lang
;
60 using namespace com::sun::star::i18n
;
61 using namespace com::sun::star::frame
;
62 using namespace com::sun::star::beans
;
65 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
67 const sal_Char cIsKernAsianPunctuation
[] = "IsKernAsianPunctuation";
68 const sal_Char cCharacterCompressionType
[] = "CharacterCompressionType";
70 struct SvxForbiddenChars_Impl
73 ForbiddenCharacters
* pCharacters
;
76 DECLARE_TABLE( _SvxForbiddenCharacterTable_Impl
, SvxForbiddenChars_Impl
* )
78 class SvxForbiddenCharacterTable_Impl
: public _SvxForbiddenCharacterTable_Impl
81 SvxForbiddenCharacterTable_Impl()
82 : _SvxForbiddenCharacterTable_Impl( 4, 4 )
84 ~SvxForbiddenCharacterTable_Impl();
87 struct SvxAsianLayoutPage_Impl
89 SvxAsianConfig aConfig
;
90 SvxAsianLayoutPage_Impl() :
93 Reference
< XForbiddenCharacters
> xForbidden
;
94 Reference
< XPropertySet
> xPrSet
;
95 Reference
< XPropertySetInfo
> xPrSetInfo
;
96 SvxForbiddenCharacterTable_Impl aChangedLanguagesTbl
;
98 sal_Bool
hasForbiddenCharacters(LanguageType eLang
);
99 SvxForbiddenChars_Impl
* getForbiddenCharacters(LanguageType eLang
);
100 void addForbiddenCharacters(LanguageType eLang
, ForbiddenCharacters
* pForbidden
);
102 /* -----------------------------24.01.01 14:50--------------------------------
104 ---------------------------------------------------------------------------*/
105 SvxForbiddenCharacterTable_Impl::~SvxForbiddenCharacterTable_Impl()
107 for( SvxForbiddenChars_Impl
* pDel
= First(); pDel
; pDel
= Next() )
109 delete pDel
->pCharacters
;
113 /* -----------------------------24.01.01 14:50--------------------------------
115 ---------------------------------------------------------------------------*/
116 sal_Bool
SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang
)
118 return 0 != aChangedLanguagesTbl
.Get(eLang
);
120 /* -----------------------------24.01.01 14:50--------------------------------
122 ---------------------------------------------------------------------------*/
123 SvxForbiddenChars_Impl
* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang
)
125 SvxForbiddenChars_Impl
* pImp
= aChangedLanguagesTbl
.Get(eLang
);
126 DBG_ASSERT(pImp
, "language not available");
131 /* -----------------------------24.01.01 14:50--------------------------------
133 ---------------------------------------------------------------------------*/
134 void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
135 LanguageType eLang
, ForbiddenCharacters
* pForbidden
)
137 SvxForbiddenChars_Impl
* pOld
= aChangedLanguagesTbl
.Get(eLang
);
140 pOld
= new SvxForbiddenChars_Impl
;
141 pOld
->bRemoved
= 0 == pForbidden
;
142 pOld
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
143 aChangedLanguagesTbl
.Insert( eLang
, pOld
);
147 pOld
->bRemoved
= 0 == pForbidden
;
148 delete pOld
->pCharacters
;
149 pOld
->pCharacters
= pForbidden
? new ForbiddenCharacters(*pForbidden
) : 0;
153 /*-- 09.01.01 13:29:02---------------------------------------------------
155 -----------------------------------------------------------------------*/
156 static LanguageType eLastUsedLanguageTypeForForbiddenCharacters
= USHRT_MAX
;
158 SvxAsianLayoutPage::SvxAsianLayoutPage( Window
* pParent
, const SfxItemSet
& rSet
) :
159 SfxTabPage(pParent
, SVX_RES( RID_SVXPAGE_ASIAN_LAYOUT
), rSet
),
160 aKerningGB( this, SVX_RES(GB_KERNING
)),
161 aCharKerningRB( this, SVX_RES(RB_CHAR_KERNING
)),
162 aCharPunctKerningRB( this, SVX_RES(RB_CHAR_PUNCT
)),
163 aCharDistGB( this, SVX_RES(GB_CHAR_DIST
)),
164 aNoCompressionRB( this, SVX_RES(RB_NO_COMP
)),
165 aPunctCompressionRB( this, SVX_RES(RB_PUNCT_COMP
)),
166 aPunctKanaCompressionRB(this, SVX_RES(RB_PUNCT_KANA_COMP
)),
167 aStartEndGB( this, SVX_RES(GB_START_END
)),
168 aLanguageFT( this, SVX_RES(FT_LANGUAGE
)),
169 aLanguageLB( this, SVX_RES(LB_LANGUAGE
)),
170 aStandardCB( this, SVX_RES(CB_STANDARD
)),
171 aStartFT( this, SVX_RES(FT_START
)),
172 aStartED( this, SVX_RES(ED_START
)),
173 aEndFT( this, SVX_RES(FT_END
)),
174 aEndED( this, SVX_RES(ED_END
)),
175 aHintFT( this, SVX_RES(FT_HINT
)),
176 pImpl(new SvxAsianLayoutPage_Impl
)
179 LanguageHdl(&aLanguageLB
);
180 aLanguageLB
.SetSelectHdl(LINK(this, SvxAsianLayoutPage
, LanguageHdl
));
181 aStandardCB
.SetClickHdl(LINK(this, SvxAsianLayoutPage
, ChangeStandardHdl
));
182 Link
aLk(LINK(this, SvxAsianLayoutPage
, ModifyHdl
));
183 aStartED
.SetModifyHdl(aLk
);
184 aEndED
.SetModifyHdl(aLk
);
186 aLanguageLB
.SetLanguageList( LANG_LIST_FBD_CHARS
, FALSE
, FALSE
);
188 /*-- 09.01.01 13:29:02---------------------------------------------------
190 -----------------------------------------------------------------------*/
191 SvxAsianLayoutPage::~SvxAsianLayoutPage()
195 /*-- 09.01.01 13:29:02---------------------------------------------------
197 -----------------------------------------------------------------------*/
198 SfxTabPage
* SvxAsianLayoutPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
200 return new SvxAsianLayoutPage(pParent
, rAttrSet
);
202 /*-- 09.01.01 13:29:03---------------------------------------------------
204 -----------------------------------------------------------------------*/
205 BOOL
SvxAsianLayoutPage::FillItemSet( SfxItemSet
& )
207 if(aCharKerningRB
.IsChecked() != aCharKerningRB
.GetSavedValue())
209 pImpl
->aConfig
.SetKerningWesternTextOnly(aCharKerningRB
.IsChecked());
210 OUString
sPunct(C2U(cIsKernAsianPunctuation
));
211 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
214 BOOL bVal
= !aCharKerningRB
.IsChecked();
215 aVal
.setValue(&bVal
, ::getBooleanCppuType());
216 pImpl
->xPrSet
->setPropertyValue(sPunct
, aVal
);
220 if(aNoCompressionRB
.IsChecked() != aNoCompressionRB
.GetSavedValue() ||
221 aPunctCompressionRB
.IsChecked() != aPunctCompressionRB
.GetSavedValue())
223 sal_Int16 nSet
= aNoCompressionRB
.IsChecked() ? 0 :
224 aPunctCompressionRB
.IsChecked() ? 1 : 2;
225 pImpl
->aConfig
.SetCharDistanceCompression(nSet
);
226 OUString
sCompress(C2U(cCharacterCompressionType
));
227 if(pImpl
->xPrSetInfo
.is() && pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
231 pImpl
->xPrSet
->setPropertyValue(sCompress
, aVal
);
234 if(pImpl
->aConfig
.IsModified())
235 pImpl
->aConfig
.Commit();
236 if(pImpl
->xForbidden
.is())
240 for( SvxForbiddenChars_Impl
* pElem
= pImpl
->aChangedLanguagesTbl
.First();
241 pElem
; pElem
= pImpl
->aChangedLanguagesTbl
.Next() )
243 ULONG nLang
= pImpl
->aChangedLanguagesTbl
.GetKey( pElem
);
245 SvxLanguageToLocale(aLocale
, (USHORT
)nLang
);
247 pImpl
->xForbidden
->removeForbiddenCharacters( aLocale
);
248 else if(pElem
->pCharacters
)
249 pImpl
->xForbidden
->setForbiddenCharacters( aLocale
, *pElem
->pCharacters
);
254 DBG_ERROR("exception in XForbiddenCharacters");
257 eLastUsedLanguageTypeForForbiddenCharacters
= aLanguageLB
.GetSelectLanguage();
261 /*-- 09.01.01 13:29:03---------------------------------------------------
263 -----------------------------------------------------------------------*/
264 void SvxAsianLayoutPage::Reset( const SfxItemSet
& )
266 SfxViewFrame
* pCurFrm
= SfxViewFrame::Current();
267 SfxObjectShell
* pDocSh
= pCurFrm
? pCurFrm
->GetObjectShell() : 0;
268 Reference
< XModel
> xModel
;
270 xModel
= pDocSh
->GetModel();
271 Reference
<XMultiServiceFactory
> xFact(xModel
, UNO_QUERY
);
274 pImpl
->xPrSet
= Reference
<XPropertySet
>(
275 xFact
->createInstance(C2U("com.sun.star.document.Settings")), UNO_QUERY
);
277 if( pImpl
->xPrSet
.is() )
278 pImpl
->xPrSetInfo
= pImpl
->xPrSet
->getPropertySetInfo();
279 OUString
sForbidden(C2U("ForbiddenCharacters"));
280 sal_Bool bKernWesternText
= pImpl
->aConfig
.IsKerningWesternTextOnly();
281 sal_Int16 nCompress
= pImpl
->aConfig
.GetCharDistanceCompression();
282 if(pImpl
->xPrSetInfo
.is())
284 if(pImpl
->xPrSetInfo
->hasPropertyByName(sForbidden
))
286 Any aForbidden
= pImpl
->xPrSet
->getPropertyValue(sForbidden
);
287 aForbidden
>>= pImpl
->xForbidden
;
289 OUString
sCompress(C2U(cCharacterCompressionType
));
290 if(pImpl
->xPrSetInfo
->hasPropertyByName(sCompress
))
292 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sCompress
);
295 OUString
sPunct(C2U(cIsKernAsianPunctuation
));
296 if(pImpl
->xPrSetInfo
->hasPropertyByName(sPunct
))
298 Any aVal
= pImpl
->xPrSet
->getPropertyValue(sPunct
);
299 bKernWesternText
= !*(sal_Bool
*)aVal
.getValue();
304 aStartEndGB
.Enable(FALSE
);
305 aLanguageFT
.Enable(FALSE
);
306 aLanguageLB
.Enable(FALSE
);
307 aStandardCB
.Enable(FALSE
);
308 aStartFT
.Enable(FALSE
);
309 aStartED
.Enable(FALSE
);
310 aEndFT
.Enable(FALSE
);
311 aEndED
.Enable(FALSE
);
312 aHintFT
.Enable(FALSE
);
315 aCharKerningRB
.Check(TRUE
);
317 aCharPunctKerningRB
.Check(TRUE
);
320 case 0 : aNoCompressionRB
.Check(); break;
321 case 1 : aPunctCompressionRB
.Check(); break;
322 default: aPunctKanaCompressionRB
.Check();
324 aCharKerningRB
.SaveValue();
325 aNoCompressionRB
.SaveValue();
326 aPunctCompressionRB
.SaveValue();
327 aPunctKanaCompressionRB
.SaveValue();
329 aLanguageLB
.SelectEntryPos(0);
330 //preselect the system language in the box - if available
331 if(USHRT_MAX
== eLastUsedLanguageTypeForForbiddenCharacters
)
333 eLastUsedLanguageTypeForForbiddenCharacters
= SvxLocaleToLanguage(
334 Application::GetSettings().GetLocale() );
335 switch(eLastUsedLanguageTypeForForbiddenCharacters
)
337 case LANGUAGE_CHINESE
:
338 case LANGUAGE_CHINESE_SINGAPORE
:
339 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_SIMPLIFIED
;
341 case LANGUAGE_CHINESE_HONGKONG
:
342 case LANGUAGE_CHINESE_MACAU
:
343 eLastUsedLanguageTypeForForbiddenCharacters
= LANGUAGE_CHINESE_TRADITIONAL
;
347 aLanguageLB
.SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters
);
348 LanguageHdl(&aLanguageLB
);
350 /* -----------------------------17.01.01 11:02--------------------------------
352 ---------------------------------------------------------------------------*/
353 IMPL_LINK(SvxAsianLayoutPage
, LanguageHdl
, SvxLanguageBox
*, EMPTYARG
)
357 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
358 SvxLanguageToLocale(aLocale
, eSelectLanguage
);
360 OUString sStart
, sEnd
;
362 if(pImpl
->xForbidden
.is())
364 bAvail
= pImpl
->hasForbiddenCharacters(eSelectLanguage
);
367 SvxForbiddenChars_Impl
* pElement
= pImpl
->getForbiddenCharacters(eSelectLanguage
);
368 if(pElement
->bRemoved
|| !pElement
->pCharacters
)
374 sStart
= pElement
->pCharacters
->beginLine
;
375 sEnd
= pElement
->pCharacters
->endLine
;
382 bAvail
= pImpl
->xForbidden
->hasForbiddenCharacters(aLocale
);
385 ForbiddenCharacters aForbidden
= pImpl
->xForbidden
->getForbiddenCharacters( aLocale
);
386 sStart
= aForbidden
.beginLine
;
387 sEnd
= aForbidden
.endLine
;
392 DBG_ERROR("exception in XForbiddenCharacters");
398 bAvail
= pImpl
->aConfig
.GetStartEndChars( aLocale
, sStart
, sEnd
);
402 Reference
< XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
403 LocaleDataWrapper
aWrap( xMSF
, aLocale
);
404 ForbiddenCharacters aForbidden
= aWrap
.getForbiddenCharacters();
405 sStart
= aForbidden
.beginLine
;
406 sEnd
= aForbidden
.endLine
;
408 aStandardCB
.Check(!bAvail
);
409 aStartED
.Enable(bAvail
);
410 aEndED
.Enable(bAvail
);
411 aStartFT
.Enable(bAvail
);
412 aEndFT
.Enable(bAvail
);
413 aStartED
.SetText(sStart
);
414 aEndED
.SetText(sEnd
);
418 /* -----------------------------17.01.01 11:02--------------------------------
420 ---------------------------------------------------------------------------*/
421 IMPL_LINK(SvxAsianLayoutPage
, ChangeStandardHdl
, CheckBox
*, pBox
)
423 sal_Bool bCheck
= pBox
->IsChecked();
424 aStartED
.Enable(!bCheck
);
425 aEndED
.Enable(!bCheck
);
426 aStartFT
.Enable(!bCheck
);
427 aEndFT
.Enable(!bCheck
);
429 ModifyHdl(&aStartED
);
432 /* -----------------------------17.01.01 12:26--------------------------------
434 ---------------------------------------------------------------------------*/
435 IMPL_LINK(SvxAsianLayoutPage
, ModifyHdl
, Edit
*, pEdit
)
438 LanguageType eSelectLanguage
= aLanguageLB
.GetSelectLanguage();
439 SvxLanguageToLocale(aLocale
, eSelectLanguage
);
440 OUString sStart
= aStartED
.GetText();
441 OUString sEnd
= aEndED
.GetText();
442 sal_Bool bEnable
= pEdit
->IsEnabled();
443 if(pImpl
->xForbidden
.is())
449 ForbiddenCharacters aSet
;
450 aSet
.beginLine
= sStart
;
452 // pImpl->xForbidden->setForbiddenCharacters( aLocale, aSet );
453 pImpl
->addForbiddenCharacters(eSelectLanguage
, &aSet
);
456 pImpl
->addForbiddenCharacters(eSelectLanguage
, 0);
457 // pImpl->xForbidden->removeForbiddenCharacters( aLocale );
461 DBG_ERROR("exception in XForbiddenCharacters");
464 pImpl
->aConfig
.SetStartEndChars( aLocale
, bEnable
? &sStart
: 0, bEnable
? &sEnd
: 0);
467 /*-- 07.09.2007 12:05:09---------------------------------------------------
469 -----------------------------------------------------------------------*/
470 USHORT
* SvxAsianLayoutPage::GetRanges()
473 static USHORT pAsianLayoutRanges
[] = { 0 };
474 return pAsianLayoutRanges
;