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_translation_unodialog.hxx"
28 #include "chinese_translationdialog.hxx"
29 #include <osl/mutex.hxx>
30 #include <vos/mutex.hxx>
31 // header for class Application
32 #include <vcl/svapp.hxx>
33 #include <toolkit/awt/vclxwindow.hxx>
34 // header for define RET_CANCEL
35 #include <vcl/msgbox.hxx>
36 
37 // header for class OImplementationId
38 #include <cppuhelper/typeprovider.hxx>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/frame/XDesktop.hpp>
41 #include <com/sun/star/frame/XDispatch.hpp>
42 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
43 
44 //.............................................................................
45 namespace textconversiondlgs
46 {
47 //.............................................................................
48 using namespace ::com::sun::star;
49 
50 #define SERVICE_IMPLEMENTATION_NAME ::rtl::OUString::createFromAscii("com.sun.star.comp.linguistic2.ChineseTranslationDialog")
51 #define SERVICE_NAME ::rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
52 
53 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
54 
ChineseTranslation_UnoDialog(const uno::Reference<uno::XComponentContext> & xContext)55 ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog( const uno::Reference< uno::XComponentContext >& xContext )
56                     : m_xCC( xContext )
57                     , m_xParentWindow( 0 )
58                     , m_pDialog( 0 )
59                     , m_bDisposed(sal_False)
60                     , m_bInDispose(sal_False)
61                     , m_aContainerMutex()
62                     , m_aDisposeEventListeners(m_aContainerMutex)
63 {
64 }
65 
~ChineseTranslation_UnoDialog()66 ChineseTranslation_UnoDialog::~ChineseTranslation_UnoDialog()
67 {
68     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
69 	impl_DeleteDialog();
70 }
71 
impl_DeleteDialog()72 void ChineseTranslation_UnoDialog::impl_DeleteDialog()
73 {
74     if( m_pDialog )
75     {
76         if(m_pDialog->IsInExecute())
77             m_pDialog->EndDialog(RET_CANCEL);
78         delete m_pDialog;
79         m_pDialog = 0;
80     }
81 }
82 //-------------------------------------------------------------------------
83 // lang::XServiceInfo
84 
getImplementationName()85 ::rtl::OUString SAL_CALL ChineseTranslation_UnoDialog::getImplementationName() throw( uno::RuntimeException )
86 {
87 	return getImplementationName_Static();
88 }
89 
getImplementationName_Static()90 ::rtl::OUString ChineseTranslation_UnoDialog::getImplementationName_Static()
91 {
92 	return SERVICE_IMPLEMENTATION_NAME;
93 }
94 
supportsService(const::rtl::OUString & ServiceName)95 sal_Bool SAL_CALL ChineseTranslation_UnoDialog::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
96 {
97 	uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
98 	const ::rtl::OUString* pArray = aSNL.getArray();
99 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
100 	{
101 		if( pArray[ i ] == ServiceName )
102 			return sal_True;
103 	}
104 	return sal_False;
105 }
106 
getSupportedServiceNames()107 uno::Sequence< ::rtl::OUString > SAL_CALL ChineseTranslation_UnoDialog::getSupportedServiceNames() throw( uno::RuntimeException )
108 {
109 	return getSupportedServiceNames_Static();
110 }
111 
getSupportedServiceNames_Static()112 uno::Sequence< rtl::OUString > ChineseTranslation_UnoDialog::getSupportedServiceNames_Static()
113 {
114 	uno::Sequence< rtl::OUString > aSNS( 1 );
115 	aSNS.getArray()[ 0 ] = SERVICE_NAME;
116 	return aSNS;
117 }
118 
119 //-------------------------------------------------------------------------
120 // ui::dialogs::XExecutableDialog
121 
setTitle(const::rtl::OUString &)122 void SAL_CALL ChineseTranslation_UnoDialog::setTitle( const ::rtl::OUString& ) throw(uno::RuntimeException)
123 {
124     //not implemented - fell free to do so, if you do need this
125 }
126 
127 //-------------------------------------------------------------------------
initialize(const uno::Sequence<uno::Any> & aArguments)128 void SAL_CALL ChineseTranslation_UnoDialog::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException)
129 {
130     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
131     if( m_bDisposed || m_bInDispose )
132         return;
133 
134 	const uno::Any* pArguments = aArguments.getConstArray();
135 	for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
136 	{
137         beans::PropertyValue aProperty;
138 		if(*pArguments >>= aProperty)
139 		{
140 			if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
141 			{
142 				aProperty.Value >>= m_xParentWindow;
143 			}
144 		}
145 	}
146 }
147 
148 //-------------------------------------------------------------------------
execute()149 sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute() throw(uno::RuntimeException)
150 {
151     sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
152     {
153         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
154         if( m_bDisposed || m_bInDispose )
155             return nRet;
156 
157 	    if( !m_pDialog )
158 	    {
159 		    Window* pParent = NULL;
160 		    if( m_xParentWindow.is() )
161 		    {
162 			    VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
163 			    if (pImplementation)
164 				    pParent = pImplementation->GetWindow();
165 		    }
166             uno::Reference< XComponent > xComp( this );
167             m_pDialog = new ChineseTranslationDialog( pParent );
168 	    }
169         if( !m_pDialog )
170             return nRet;
171         nRet = m_pDialog->Execute();
172         if(nRet==RET_OK)
173            nRet=ui::dialogs::ExecutableDialogResults::OK;
174     }
175     return nRet;
176 }
177 
178 //-------------------------------------------------------------------------
179 // lang::XComponent
180 
dispose()181 void SAL_CALL ChineseTranslation_UnoDialog::dispose() throw (uno::RuntimeException)
182 {
183     lang::EventObject aEvt;
184     {
185         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
186         if( m_bDisposed || m_bInDispose )
187             return;
188         m_bInDispose = true;
189 
190         impl_DeleteDialog();
191         m_xParentWindow = 0;
192         m_bDisposed = true;
193 
194         aEvt.Source = static_cast< XComponent * >( this );
195     }
196     if( m_aDisposeEventListeners.getLength() )
197 		m_aDisposeEventListeners.disposeAndClear( aEvt );
198 }
199 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)200 void SAL_CALL ChineseTranslation_UnoDialog::addEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
201 {
202     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
203     if( m_bDisposed || m_bInDispose )
204         return;
205     m_aDisposeEventListeners.addInterface( xListener );
206 }
207 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)208 void SAL_CALL ChineseTranslation_UnoDialog::removeEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
209 {
210     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
211     if( m_bDisposed || m_bInDispose )
212         return;
213     m_aDisposeEventListeners.removeInterface( xListener );
214 }
215 
216 //-------------------------------------------------------------------------
217 // XPropertySet
218 
getPropertySetInfo()219 uno::Reference< beans::XPropertySetInfo > SAL_CALL ChineseTranslation_UnoDialog::getPropertySetInfo(  ) throw (uno::RuntimeException)
220 {
221     return 0;
222 }
setPropertyValue(const::rtl::OUString &,const uno::Any &)223 void SAL_CALL ChineseTranslation_UnoDialog::setPropertyValue( const ::rtl::OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
224 {
225     //only read only properties
226     throw beans::PropertyVetoException();
227 }
getPropertyValue(const::rtl::OUString & rPropertyName)228 uno::Any SAL_CALL ChineseTranslation_UnoDialog::getPropertyValue( const ::rtl::OUString& rPropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
229 {
230     uno::Any aRet;
231 
232     sal_Bool bDirectionToSimplified = sal_True;
233     sal_Bool bUseCharacterVariants = sal_False;
234     sal_Bool bTranslateCommonTerms = sal_False;
235 
236     {
237         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
238         if( m_bDisposed || m_bInDispose || !m_pDialog )
239             return aRet;
240         m_pDialog->getSettings( bDirectionToSimplified, bUseCharacterVariants, bTranslateCommonTerms );
241     }
242 
243     if( rPropertyName.equals( C2U("IsDirectionToSimplified") ) )
244     {
245         aRet <<= bDirectionToSimplified;
246     }
247     else if( rPropertyName.equals( C2U("IsUseCharacterVariants") ) )
248     {
249         aRet <<= bUseCharacterVariants;
250     }
251     else if( rPropertyName.equals( C2U("IsTranslateCommonTerms") ) )
252     {
253         aRet <<= bTranslateCommonTerms;
254     }
255     else
256     {
257         throw beans::UnknownPropertyException();
258     }
259     return aRet;
260 
261 }
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)262 void SAL_CALL ChineseTranslation_UnoDialog::addPropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
263 {
264     //only not bound properties -> ignore listener
265 }
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)266 void SAL_CALL ChineseTranslation_UnoDialog::removePropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
267 {
268     //only not bound properties -> ignore listener
269 }
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)270 void SAL_CALL ChineseTranslation_UnoDialog::addVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
271 {
272     //only not bound properties -> ignore listener
273 }
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)274 void SAL_CALL ChineseTranslation_UnoDialog::removeVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
275 {
276     //only not bound properties -> ignore listener
277 }
278 
279 //.............................................................................
280 } //end namespace
281 //.............................................................................
282