Update ooo320-m1
[ooovba.git] / svx / source / unodialogs / textconversiondlgs / chinese_translation_unodialog.cxx
blob68a66235983d89599fc28988ebe9b7a886179ce4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chinese_translation_unodialog.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "chinese_translation_unodialog.hxx"
35 #include "chinese_translationdialog.hxx"
36 #include <osl/mutex.hxx>
37 #include <vos/mutex.hxx>
38 // header for class Application
39 #include <vcl/svapp.hxx>
40 #include <toolkit/awt/vclxwindow.hxx>
41 // header for define RET_CANCEL
42 #include <vcl/msgbox.hxx>
44 // header for class OImplementationId
45 #include <cppuhelper/typeprovider.hxx>
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 #include <com/sun/star/frame/XDesktop.hpp>
48 #include <com/sun/star/frame/XDispatch.hpp>
49 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
51 //.............................................................................
52 namespace textconversiondlgs
54 //.............................................................................
55 using namespace ::com::sun::star;
57 #define SERVICE_IMPLEMENTATION_NAME ::rtl::OUString::createFromAscii("com.sun.star.comp.linguistic2.ChineseTranslationDialog")
58 #define SERVICE_NAME ::rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
60 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
62 ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog( const uno::Reference< uno::XComponentContext >& xContext )
63 : m_xCC( xContext )
64 , m_xParentWindow( 0 )
65 , m_pDialog( 0 )
66 , m_bDisposed(sal_False)
67 , m_bInDispose(sal_False)
68 , m_aContainerMutex()
69 , m_aDisposeEventListeners(m_aContainerMutex)
73 ChineseTranslation_UnoDialog::~ChineseTranslation_UnoDialog()
75 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
76 impl_DeleteDialog();
79 void ChineseTranslation_UnoDialog::impl_DeleteDialog()
81 if( m_pDialog )
83 if(m_pDialog->IsInExecute())
84 m_pDialog->EndDialog(RET_CANCEL);
85 delete m_pDialog;
86 m_pDialog = 0;
89 //-------------------------------------------------------------------------
90 // lang::XServiceInfo
92 ::rtl::OUString SAL_CALL ChineseTranslation_UnoDialog::getImplementationName() throw( uno::RuntimeException )
94 return getImplementationName_Static();
97 ::rtl::OUString ChineseTranslation_UnoDialog::getImplementationName_Static()
99 return SERVICE_IMPLEMENTATION_NAME;
102 sal_Bool SAL_CALL ChineseTranslation_UnoDialog::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
104 uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
105 const ::rtl::OUString* pArray = aSNL.getArray();
106 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
108 if( pArray[ i ] == ServiceName )
109 return sal_True;
111 return sal_False;
114 uno::Sequence< ::rtl::OUString > SAL_CALL ChineseTranslation_UnoDialog::getSupportedServiceNames() throw( uno::RuntimeException )
116 return getSupportedServiceNames_Static();
119 uno::Sequence< rtl::OUString > ChineseTranslation_UnoDialog::getSupportedServiceNames_Static()
121 uno::Sequence< rtl::OUString > aSNS( 1 );
122 aSNS.getArray()[ 0 ] = SERVICE_NAME;
123 return aSNS;
126 //-------------------------------------------------------------------------
127 // ui::dialogs::XExecutableDialog
129 void SAL_CALL ChineseTranslation_UnoDialog::setTitle( const ::rtl::OUString& ) throw(uno::RuntimeException)
131 //not implemented - fell free to do so, if you do need this
134 //-------------------------------------------------------------------------
135 void SAL_CALL ChineseTranslation_UnoDialog::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException)
137 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
138 if( m_bDisposed || m_bInDispose )
139 return;
141 const uno::Any* pArguments = aArguments.getConstArray();
142 for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
144 beans::PropertyValue aProperty;
145 if(*pArguments >>= aProperty)
147 if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
149 aProperty.Value >>= m_xParentWindow;
155 //-------------------------------------------------------------------------
156 sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute() throw(uno::RuntimeException)
158 sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
160 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
161 if( m_bDisposed || m_bInDispose )
162 return nRet;
164 if( !m_pDialog )
166 Window* pParent = NULL;
167 if( m_xParentWindow.is() )
169 VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
170 if (pImplementation)
171 pParent = pImplementation->GetWindow();
173 uno::Reference< XComponent > xComp( this );
174 m_pDialog = new ChineseTranslationDialog( pParent );
176 if( !m_pDialog )
177 return nRet;
178 nRet = m_pDialog->Execute();
179 if(nRet==RET_OK)
180 nRet=ui::dialogs::ExecutableDialogResults::OK;
182 return nRet;
185 //-------------------------------------------------------------------------
186 // lang::XComponent
188 void SAL_CALL ChineseTranslation_UnoDialog::dispose() throw (uno::RuntimeException)
190 lang::EventObject aEvt;
192 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
193 if( m_bDisposed || m_bInDispose )
194 return;
195 m_bInDispose = true;
197 impl_DeleteDialog();
198 m_xParentWindow = 0;
199 m_bDisposed = true;
201 aEvt.Source = static_cast< XComponent * >( this );
203 if( m_aDisposeEventListeners.getLength() )
204 m_aDisposeEventListeners.disposeAndClear( aEvt );
207 void SAL_CALL ChineseTranslation_UnoDialog::addEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
209 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
210 if( m_bDisposed || m_bInDispose )
211 return;
212 m_aDisposeEventListeners.addInterface( xListener );
215 void SAL_CALL ChineseTranslation_UnoDialog::removeEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException)
217 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
218 if( m_bDisposed || m_bInDispose )
219 return;
220 m_aDisposeEventListeners.removeInterface( xListener );
223 //-------------------------------------------------------------------------
224 // XPropertySet
226 uno::Reference< beans::XPropertySetInfo > SAL_CALL ChineseTranslation_UnoDialog::getPropertySetInfo( ) throw (uno::RuntimeException)
228 return 0;
230 void SAL_CALL ChineseTranslation_UnoDialog::setPropertyValue( const ::rtl::OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
232 //only read only properties
233 throw beans::PropertyVetoException();
235 uno::Any SAL_CALL ChineseTranslation_UnoDialog::getPropertyValue( const ::rtl::OUString& rPropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
237 uno::Any aRet;
239 sal_Bool bDirectionToSimplified = sal_True;
240 sal_Bool bUseCharacterVariants = sal_False;
241 sal_Bool bTranslateCommonTerms = sal_False;
244 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
245 if( m_bDisposed || m_bInDispose || !m_pDialog )
246 return aRet;
247 m_pDialog->getSettings( bDirectionToSimplified, bUseCharacterVariants, bTranslateCommonTerms );
250 if( rPropertyName.equals( C2U("IsDirectionToSimplified") ) )
252 aRet <<= bDirectionToSimplified;
254 else if( rPropertyName.equals( C2U("IsUseCharacterVariants") ) )
256 aRet <<= bUseCharacterVariants;
258 else if( rPropertyName.equals( C2U("IsTranslateCommonTerms") ) )
260 aRet <<= bTranslateCommonTerms;
262 else
264 throw beans::UnknownPropertyException();
266 return aRet;
269 void SAL_CALL ChineseTranslation_UnoDialog::addPropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
271 //only not bound properties -> ignore listener
273 void SAL_CALL ChineseTranslation_UnoDialog::removePropertyChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
275 //only not bound properties -> ignore listener
277 void SAL_CALL ChineseTranslation_UnoDialog::addVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
279 //only not bound properties -> ignore listener
281 void SAL_CALL ChineseTranslation_UnoDialog::removeVetoableChangeListener( const ::rtl::OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
283 //only not bound properties -> ignore listener
286 //.............................................................................
287 } //end namespace
288 //.............................................................................