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