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