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