1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "chinese_translationdialog.hxx"
28cdf0e10cSrcweir #include "chinese_translationdialog.hrc"
29cdf0e10cSrcweir #include "resid.hxx"
30cdf0e10cSrcweir #include "chinese_dictionarydialog.hxx"
31cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hpp>
32cdf0e10cSrcweir // header for define RET_OK
33cdf0e10cSrcweir #include <vcl/msgbox.hxx>
34cdf0e10cSrcweir // header for class SvtLinguConfigItem
35cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
36cdf0e10cSrcweir #include <unotools/linguprops.hxx>
37cdf0e10cSrcweir #ifndef _SVX_HELPID_HRC
38cdf0e10cSrcweir #include "helpid.hrc"
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //disable compiler warning C4355: 'this' : used in base member initializer list
42cdf0e10cSrcweir #ifdef _MSC_VER
43cdf0e10cSrcweir #  pragma warning (disable : 4355)
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //.............................................................................
47cdf0e10cSrcweir namespace textconversiondlgs
48cdf0e10cSrcweir {
49cdf0e10cSrcweir //.............................................................................
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53cdf0e10cSrcweir 
ChineseTranslationDialog(Window * pParent)54cdf0e10cSrcweir ChineseTranslationDialog::ChineseTranslationDialog( Window* pParent )
55cdf0e10cSrcweir     : ModalDialog( pParent, TextConversionDlgs_ResId( DLG_CHINESETRANSLATION ) )
56cdf0e10cSrcweir     , m_aFL_Direction( this, TextConversionDlgs_ResId( FL_DIRECTION ) )
57cdf0e10cSrcweir     , m_aRB_To_Simplified( this, TextConversionDlgs_ResId( RB_TO_SIMPLIFIED ) )
58cdf0e10cSrcweir     , m_aRB_To_Traditional( this, TextConversionDlgs_ResId( RB_TO_TRADITIONAL ) )
59cdf0e10cSrcweir     , m_aCB_Use_Variants( this, TextConversionDlgs_ResId( CB_USE_VARIANTS ) )
60cdf0e10cSrcweir     , m_aFL_Commonterms( this, TextConversionDlgs_ResId( FL_COMMONTERMS ) )
61cdf0e10cSrcweir     , m_aCB_Translate_Commonterms( this, TextConversionDlgs_ResId( CB_TRANSLATE_COMMONTERMS ) )
62cdf0e10cSrcweir     , m_aPB_Editterms( this, TextConversionDlgs_ResId( PB_EDITTERMS ) )
63cdf0e10cSrcweir     , m_aFL_Bottomline( this, TextConversionDlgs_ResId( T_FL_BOTTOMLINE ) )
64cdf0e10cSrcweir     , m_aBP_OK( this, TextConversionDlgs_ResId( PB_OK ) )
65cdf0e10cSrcweir     , m_aBP_Cancel( this, TextConversionDlgs_ResId( PB_CANCEL ) )
66cdf0e10cSrcweir     , m_aBP_Help( this, TextConversionDlgs_ResId( PB_HELP ) )
67cdf0e10cSrcweir     , m_pDictionaryDialog(0)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     FreeResource();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     m_aRB_To_Simplified.SetHelpId( HID_SVX_CHINESE_TRANSLATION_RB_CONVERSION_TO_SIMPLIFIED );
72cdf0e10cSrcweir     m_aRB_To_Traditional.SetHelpId( HID_SVX_CHINESE_TRANSLATION_RB_CONVERSION_TO_TRADITIONAL );
73cdf0e10cSrcweir     m_aCB_Use_Variants.SetHelpId( HID_SVX_CHINESE_TRANSLATION_CB_USE_VARIANTS );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     SvtLinguConfig	aLngCfg;
76cdf0e10cSrcweir     sal_Bool bValue = sal_Bool();
77cdf0e10cSrcweir     Any aAny( aLngCfg.GetProperty( rtl::OUString::createFromAscii( UPN_IS_DIRECTION_TO_SIMPLIFIED ) ) );
78cdf0e10cSrcweir     aAny >>= bValue;
79cdf0e10cSrcweir     if( bValue )
80cdf0e10cSrcweir         m_aRB_To_Simplified.Check();
81cdf0e10cSrcweir     else
82cdf0e10cSrcweir         m_aRB_To_Traditional.Check();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     aAny = aLngCfg.GetProperty( rtl::OUString::createFromAscii( UPN_IS_USE_CHARACTER_VARIANTS ) );
85cdf0e10cSrcweir 	if( aAny >>= bValue )
86cdf0e10cSrcweir 	    m_aCB_Use_Variants.Check( bValue );
87cdf0e10cSrcweir 
88*86e1cf34SPedro Giffuni     // #117820# (search for other occurrences!)
89cdf0e10cSrcweir     // disable and hide that checkbox until it is decided if it is needed or not.
90cdf0e10cSrcweir     // If it is to be removed later the respective code needs to be removed as
91cdf0e10cSrcweir     // well, otherwise we just have to remove the next lines again.
92cdf0e10cSrcweir     m_aCB_Use_Variants.Check( sal_False );
93cdf0e10cSrcweir     m_aCB_Use_Variants.Enable( sal_False );
94cdf0e10cSrcweir     m_aCB_Use_Variants.Show( sal_False );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     aAny = aLngCfg.GetProperty( rtl::OUString::createFromAscii( UPN_IS_TRANSLATE_COMMON_TERMS ) );
97cdf0e10cSrcweir     if( aAny >>= bValue )
98cdf0e10cSrcweir 	    m_aCB_Translate_Commonterms.Check( bValue );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     m_aPB_Editterms.SetClickHdl( LINK( this, ChineseTranslationDialog, DictionaryHdl ) );
101cdf0e10cSrcweir     m_aRB_To_Simplified.SetClickHdl( LINK( this, ChineseTranslationDialog, DirectionHdl ) );
102cdf0e10cSrcweir     m_aRB_To_Traditional.SetClickHdl( LINK( this, ChineseTranslationDialog, DirectionHdl ) );
103cdf0e10cSrcweir     m_aCB_Translate_Commonterms.SetClickHdl( LINK( this, ChineseTranslationDialog, CommonTermsHdl ) );
104cdf0e10cSrcweir     m_aBP_OK.SetClickHdl( LINK( this, ChineseTranslationDialog, OkHdl ) );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     impl_UpdateVariantsCheckBox();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
~ChineseTranslationDialog()109cdf0e10cSrcweir ChineseTranslationDialog::~ChineseTranslationDialog()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     if(m_pDictionaryDialog)
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         if(m_pDictionaryDialog->IsInExecute())
114cdf0e10cSrcweir             m_pDictionaryDialog->EndDialog();
115cdf0e10cSrcweir         delete m_pDictionaryDialog;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
getSettings(sal_Bool & rbDirectionToSimplified,sal_Bool & rbUseCharacterVariants,sal_Bool & rbTranslateCommonTerms) const119cdf0e10cSrcweir void ChineseTranslationDialog::getSettings( sal_Bool& rbDirectionToSimplified
120cdf0e10cSrcweir                                           , sal_Bool& rbUseCharacterVariants
121cdf0e10cSrcweir                                           , sal_Bool& rbTranslateCommonTerms ) const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     rbDirectionToSimplified = m_aRB_To_Simplified.IsChecked();
124cdf0e10cSrcweir     rbUseCharacterVariants = m_aCB_Use_Variants.IsChecked();
125cdf0e10cSrcweir     rbTranslateCommonTerms = m_aCB_Translate_Commonterms.IsChecked();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
impl_UpdateVariantsCheckBox()128cdf0e10cSrcweir void ChineseTranslationDialog::impl_UpdateVariantsCheckBox()
129cdf0e10cSrcweir {
130*86e1cf34SPedro Giffuni // #117820# (search for other occurrences!)
131cdf0e10cSrcweir //    m_aCB_Use_Variants.Enable( m_aRB_To_Traditional.IsChecked() );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
IMPL_LINK(ChineseTranslationDialog,DirectionHdl,void *,EMPTYARG)134cdf0e10cSrcweir IMPL_LINK( ChineseTranslationDialog, DirectionHdl, void*, EMPTYARG )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     impl_UpdateVariantsCheckBox();
137cdf0e10cSrcweir     return 0;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
IMPL_LINK(ChineseTranslationDialog,CommonTermsHdl,void *,EMPTYARG)140cdf0e10cSrcweir IMPL_LINK( ChineseTranslationDialog, CommonTermsHdl, void*, EMPTYARG )
141cdf0e10cSrcweir {
142*86e1cf34SPedro Giffuni // #117820# (search for other occurrences!)
143cdf0e10cSrcweir //    if( m_aCB_Translate_Commonterms.IsChecked() && m_aRB_To_Traditional.IsChecked() )
144cdf0e10cSrcweir //        m_aCB_Use_Variants.Check( true );
145cdf0e10cSrcweir     return 0;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
IMPL_LINK(ChineseTranslationDialog,OkHdl,void *,EMPTYARG)148cdf0e10cSrcweir IMPL_LINK( ChineseTranslationDialog, OkHdl, void*, EMPTYARG )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     //save settings to configuration
151cdf0e10cSrcweir     SvtLinguConfig	aLngCfg;
152cdf0e10cSrcweir     Any aAny;
153cdf0e10cSrcweir     aAny <<= sal_Bool( !!m_aRB_To_Simplified.IsChecked() );
154cdf0e10cSrcweir 	aLngCfg.SetProperty( rtl::OUString::createFromAscii( UPN_IS_DIRECTION_TO_SIMPLIFIED ), aAny );
155cdf0e10cSrcweir 	aAny <<= sal_Bool( !!m_aCB_Use_Variants.IsChecked() );
156cdf0e10cSrcweir 	aLngCfg.SetProperty( rtl::OUString::createFromAscii( UPN_IS_USE_CHARACTER_VARIANTS ), aAny );
157cdf0e10cSrcweir     aAny <<= sal_Bool( !!m_aCB_Translate_Commonterms.IsChecked() );
158cdf0e10cSrcweir 	aLngCfg.SetProperty( rtl::OUString::createFromAscii( UPN_IS_TRANSLATE_COMMON_TERMS ), aAny );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     EndDialog( RET_OK );
161cdf0e10cSrcweir     return 0;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
IMPL_LINK(ChineseTranslationDialog,DictionaryHdl,void *,EMPTYARG)164cdf0e10cSrcweir IMPL_LINK( ChineseTranslationDialog, DictionaryHdl, void*, EMPTYARG )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     if( !m_pDictionaryDialog )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         m_pDictionaryDialog = new ChineseDictionaryDialog(this);
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir     if( m_pDictionaryDialog )
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         if( m_pDictionaryDialog->IsInExecute() )
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             if( !m_pDictionaryDialog->IsReallyVisible() )
175cdf0e10cSrcweir             {
176cdf0e10cSrcweir                 m_pDictionaryDialog->ToTop();
177cdf0e10cSrcweir                 m_pDictionaryDialog->GrabFocusToFirstControl();
178cdf0e10cSrcweir             }
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir         else
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             sal_Int32 nTextConversionOptions = i18n::TextConversionOption::NONE;
183cdf0e10cSrcweir             if( !m_aCB_Translate_Commonterms.IsChecked() )
184cdf0e10cSrcweir                 nTextConversionOptions = nTextConversionOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
185cdf0e10cSrcweir             if( m_aCB_Use_Variants.IsChecked() )
186cdf0e10cSrcweir                 nTextConversionOptions = nTextConversionOptions | i18n::TextConversionOption::USE_CHARACTER_VARIANTS;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             m_pDictionaryDialog->setDirectionAndTextConversionOptions( m_aRB_To_Simplified.IsChecked(), nTextConversionOptions );
189cdf0e10cSrcweir             m_pDictionaryDialog->Execute();
190cdf0e10cSrcweir         }
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir     return 0;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //.............................................................................
196cdf0e10cSrcweir } //end namespace
197cdf0e10cSrcweir //.............................................................................
198