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