bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / unodialogs / textconversiondlgs / chinese_translation_unodialog.cxx
blob5c8e11f0d8db5c80fe4a36ce78401e400fe21ad6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "chinese_translation_unodialog.hxx"
22 #include "chinese_translationdialog.hxx"
23 #include <osl/mutex.hxx>
24 // header for class Application
25 #include <vcl/svapp.hxx>
26 #include <toolkit/awt/vclxwindow.hxx>
27 // header for define RET_CANCEL
28 #include <vcl/msgbox.hxx>
30 // header for class OImplementationId
31 #include <cppuhelper/typeprovider.hxx>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/frame/XDesktop.hpp>
34 #include <com/sun/star/frame/XDispatch.hpp>
35 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
37 //.............................................................................
38 namespace textconversiondlgs
40 //.............................................................................
41 using namespace ::com::sun::star;
43 #define SERVICE_IMPLEMENTATION_NAME OUString("com.sun.star.comp.linguistic2.ChineseTranslationDialog")
44 #define SERVICE_NAME OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
46 ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog( const uno::Reference< uno::XComponentContext >& xContext )
47 : m_xCC( xContext )
48 , m_xParentWindow( 0 )
49 , m_pDialog( 0 )
50 , m_bDisposed(false)
51 , m_bInDispose(false)
52 , m_aContainerMutex()
53 , m_aDisposeEventListeners(m_aContainerMutex)
57 ChineseTranslation_UnoDialog::~ChineseTranslation_UnoDialog()
59 SolarMutexGuard aSolarGuard;
60 impl_DeleteDialog();
63 void ChineseTranslation_UnoDialog::impl_DeleteDialog()
65 if( m_pDialog )
67 if(m_pDialog->IsInExecute())
68 m_pDialog->EndDialog(RET_CANCEL);
69 delete m_pDialog;
70 m_pDialog = 0;
73 //-------------------------------------------------------------------------
74 // lang::XServiceInfo
76 OUString SAL_CALL ChineseTranslation_UnoDialog::getImplementationName() throw( uno::RuntimeException )
78 return getImplementationName_Static();
81 OUString ChineseTranslation_UnoDialog::getImplementationName_Static()
83 return SERVICE_IMPLEMENTATION_NAME;
86 sal_Bool SAL_CALL ChineseTranslation_UnoDialog::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
88 uno::Sequence< OUString > aSNL = getSupportedServiceNames();
89 const OUString* pArray = aSNL.getArray();
90 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
92 if( pArray[ i ] == ServiceName )
93 return sal_True;
95 return sal_False;
98 uno::Sequence< OUString > SAL_CALL ChineseTranslation_UnoDialog::getSupportedServiceNames() throw( uno::RuntimeException )
100 return getSupportedServiceNames_Static();
103 uno::Sequence< OUString > ChineseTranslation_UnoDialog::getSupportedServiceNames_Static()
105 uno::Sequence< OUString > aSNS( 1 );
106 aSNS.getArray()[ 0 ] = SERVICE_NAME;
107 return aSNS;
110 //-------------------------------------------------------------------------
111 // ui::dialogs::XExecutableDialog
113 void SAL_CALL ChineseTranslation_UnoDialog::setTitle( const OUString& ) throw(uno::RuntimeException)
115 //not implemented - fell free to do so, if you do need this
118 //-------------------------------------------------------------------------
119 void SAL_CALL ChineseTranslation_UnoDialog::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException)
121 SolarMutexGuard aSolarGuard;
122 if( m_bDisposed || m_bInDispose )
123 return;
125 const uno::Any* pArguments = aArguments.getConstArray();
126 for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
128 beans::PropertyValue aProperty;
129 if(*pArguments >>= aProperty)
131 if( aProperty.Name == "ParentWindow" )
133 aProperty.Value >>= m_xParentWindow;
139 //-------------------------------------------------------------------------
140 sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute() throw(uno::RuntimeException)
142 sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
144 SolarMutexGuard aSolarGuard;
145 if( m_bDisposed || m_bInDispose )
146 return nRet;
148 if( !m_pDialog )
150 Window* pParent = NULL;
151 if( m_xParentWindow.is() )
153 VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
154 if (pImplementation)
155 pParent = pImplementation->GetWindow();
157 uno::Reference< XComponent > xComp( this );
158 m_pDialog = new ChineseTranslationDialog( pParent );
160 if( !m_pDialog )
161 return nRet;
162 nRet = m_pDialog->Execute();
163 if(nRet==RET_OK)
164 nRet=ui::dialogs::ExecutableDialogResults::OK;
166 return nRet;
169 //-------------------------------------------------------------------------
170 // lang::XComponent
172 void SAL_CALL ChineseTranslation_UnoDialog::dispose() throw (uno::RuntimeException)
174 lang::EventObject aEvt;
176 SolarMutexGuard aSolarGuard;
177 if( m_bDisposed || m_bInDispose )
178 return;
179 m_bInDispose = true;
181 impl_DeleteDialog();
182 m_xParentWindow = 0;
183 m_bDisposed = true;
185 aEvt.Source = static_cast< XComponent * >( this );
187 if( m_aDisposeEventListeners.getLength() )
188 m_aDisposeEventListeners.disposeAndClear( aEvt );
191 void SAL_CALL ChineseTranslation_UnoDialog::addEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
193 SolarMutexGuard aSolarGuard;
194 if( m_bDisposed || m_bInDispose )
195 return;
196 m_aDisposeEventListeners.addInterface( xListener );
199 void SAL_CALL ChineseTranslation_UnoDialog::removeEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
201 SolarMutexGuard aSolarGuard;
202 if( m_bDisposed || m_bInDispose )
203 return;
204 m_aDisposeEventListeners.removeInterface( xListener );
207 //-------------------------------------------------------------------------
208 // XPropertySet
210 uno::Reference< beans::XPropertySetInfo > SAL_CALL ChineseTranslation_UnoDialog::getPropertySetInfo( ) throw (uno::RuntimeException)
212 return 0;
214 void SAL_CALL ChineseTranslation_UnoDialog::setPropertyValue( const OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
216 //only read only properties
217 throw beans::PropertyVetoException();
219 uno::Any SAL_CALL ChineseTranslation_UnoDialog::getPropertyValue( const OUString& rPropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
221 uno::Any aRet;
223 sal_Bool bDirectionToSimplified = sal_True;
224 sal_Bool bUseCharacterVariants = sal_False;
225 sal_Bool bTranslateCommonTerms = sal_False;
228 SolarMutexGuard aSolarGuard;
229 if( m_bDisposed || m_bInDispose || !m_pDialog )
230 return aRet;
231 m_pDialog->getSettings( bDirectionToSimplified, bTranslateCommonTerms );
234 if( rPropertyName.equals( "IsDirectionToSimplified" ) )
236 aRet <<= bDirectionToSimplified;
238 else if( rPropertyName.equals( "IsUseCharacterVariants" ) )
240 aRet <<= bUseCharacterVariants;
242 else if( rPropertyName.equals( "IsTranslateCommonTerms" ) )
244 aRet <<= bTranslateCommonTerms;
246 else
248 throw beans::UnknownPropertyException();
250 return aRet;
253 void SAL_CALL ChineseTranslation_UnoDialog::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
255 //only not bound properties -> ignore listener
257 void SAL_CALL ChineseTranslation_UnoDialog::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
259 //only not bound properties -> ignore listener
261 void SAL_CALL ChineseTranslation_UnoDialog::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
263 //only not bound properties -> ignore listener
265 void SAL_CALL ChineseTranslation_UnoDialog::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
267 //only not bound properties -> ignore listener
270 //.............................................................................
271 } //end namespace
272 //.............................................................................
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */