Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "chinese_translation_unodialog.hxx"
22 : #include "chinese_translationdialog.hxx"
23 : #include <osl/mutex.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <toolkit/awt/vclxwindow.hxx>
26 : #include <vcl/msgbox.hxx>
27 : #include <cppuhelper/supportsservice.hxx>
28 : #include <cppuhelper/typeprovider.hxx>
29 : #include <com/sun/star/beans/PropertyValue.hpp>
30 : #include <com/sun/star/frame/XDesktop.hpp>
31 : #include <com/sun/star/frame/XDispatch.hpp>
32 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
33 :
34 : namespace textconversiondlgs
35 : {
36 : using namespace ::com::sun::star;
37 :
38 0 : ChineseTranslation_UnoDialog::ChineseTranslation_UnoDialog( const uno::Reference< uno::XComponentContext >& xContext )
39 : : m_xCC( xContext )
40 : , m_xParentWindow( 0 )
41 : , m_pDialog( 0 )
42 : , m_bDisposed(false)
43 : , m_bInDispose(false)
44 : , m_aContainerMutex()
45 0 : , m_aDisposeEventListeners(m_aContainerMutex)
46 : {
47 0 : }
48 :
49 0 : ChineseTranslation_UnoDialog::~ChineseTranslation_UnoDialog()
50 : {
51 0 : SolarMutexGuard aSolarGuard;
52 0 : impl_DeleteDialog();
53 0 : }
54 :
55 0 : void ChineseTranslation_UnoDialog::impl_DeleteDialog()
56 : {
57 0 : if( m_pDialog )
58 : {
59 0 : if(m_pDialog->IsInExecute())
60 0 : m_pDialog->EndDialog(RET_CANCEL);
61 0 : delete m_pDialog;
62 0 : m_pDialog = 0;
63 : }
64 0 : }
65 :
66 : // lang::XServiceInfo
67 0 : OUString SAL_CALL ChineseTranslation_UnoDialog::getImplementationName() throw( uno::RuntimeException, std::exception )
68 : {
69 0 : return getImplementationName_Static();
70 : }
71 :
72 0 : OUString ChineseTranslation_UnoDialog::getImplementationName_Static()
73 : {
74 0 : return OUString("com.sun.star.comp.linguistic2.ChineseTranslationDialog");
75 : }
76 :
77 0 : sal_Bool SAL_CALL ChineseTranslation_UnoDialog::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
78 : {
79 0 : return cppu::supportsService(this, ServiceName);
80 : }
81 :
82 0 : uno::Sequence< OUString > SAL_CALL ChineseTranslation_UnoDialog::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
83 : {
84 0 : return getSupportedServiceNames_Static();
85 : }
86 :
87 0 : uno::Sequence< OUString > ChineseTranslation_UnoDialog::getSupportedServiceNames_Static()
88 : {
89 0 : uno::Sequence< OUString > aSNS( 1 );
90 0 : aSNS[ 0 ] = "com.sun.star.linguistic2.ChineseTranslationDialog";
91 0 : return aSNS;
92 : }
93 :
94 : // ui::dialogs::XExecutableDialog
95 0 : void SAL_CALL ChineseTranslation_UnoDialog::setTitle( const OUString& ) throw(uno::RuntimeException, std::exception)
96 : {
97 : //not implemented - fell free to do so, if you do need this
98 0 : }
99 :
100 :
101 0 : void SAL_CALL ChineseTranslation_UnoDialog::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException, std::exception)
102 : {
103 0 : SolarMutexGuard aSolarGuard;
104 0 : if( m_bDisposed || m_bInDispose )
105 0 : return;
106 :
107 0 : const uno::Any* pArguments = aArguments.getConstArray();
108 0 : for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
109 : {
110 0 : beans::PropertyValue aProperty;
111 0 : if(*pArguments >>= aProperty)
112 : {
113 0 : if( aProperty.Name == "ParentWindow" )
114 : {
115 0 : aProperty.Value >>= m_xParentWindow;
116 : }
117 : }
118 0 : }
119 : }
120 :
121 :
122 0 : sal_Int16 SAL_CALL ChineseTranslation_UnoDialog::execute() throw(uno::RuntimeException, std::exception)
123 : {
124 0 : sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
125 : {
126 0 : SolarMutexGuard aSolarGuard;
127 0 : if( m_bDisposed || m_bInDispose )
128 0 : return nRet;
129 :
130 0 : if( !m_pDialog )
131 : {
132 0 : vcl::Window* pParent = NULL;
133 0 : if( m_xParentWindow.is() )
134 : {
135 0 : VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
136 0 : if (pImplementation)
137 0 : pParent = pImplementation->GetWindow();
138 : }
139 0 : uno::Reference< XComponent > xComp( this );
140 0 : m_pDialog = new ChineseTranslationDialog( pParent );
141 : }
142 0 : if( !m_pDialog )
143 0 : return nRet;
144 0 : nRet = m_pDialog->Execute();
145 0 : if(nRet==RET_OK)
146 0 : nRet=ui::dialogs::ExecutableDialogResults::OK;
147 : }
148 0 : return nRet;
149 : }
150 :
151 :
152 : // lang::XComponent
153 :
154 0 : void SAL_CALL ChineseTranslation_UnoDialog::dispose() throw (uno::RuntimeException, std::exception)
155 : {
156 0 : lang::EventObject aEvt;
157 : {
158 0 : SolarMutexGuard aSolarGuard;
159 0 : if( m_bDisposed || m_bInDispose )
160 0 : return;
161 0 : m_bInDispose = true;
162 :
163 0 : impl_DeleteDialog();
164 0 : m_xParentWindow = 0;
165 0 : m_bDisposed = true;
166 :
167 0 : aEvt.Source = static_cast< XComponent * >( this );
168 : }
169 0 : if( m_aDisposeEventListeners.getLength() )
170 0 : m_aDisposeEventListeners.disposeAndClear( aEvt );
171 : }
172 :
173 0 : void SAL_CALL ChineseTranslation_UnoDialog::addEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException, std::exception)
174 : {
175 0 : SolarMutexGuard aSolarGuard;
176 0 : if( m_bDisposed || m_bInDispose )
177 0 : return;
178 0 : m_aDisposeEventListeners.addInterface( xListener );
179 : }
180 :
181 0 : void SAL_CALL ChineseTranslation_UnoDialog::removeEventListener( const uno::Reference< lang::XEventListener > & xListener ) throw (uno::RuntimeException, std::exception)
182 : {
183 0 : SolarMutexGuard aSolarGuard;
184 0 : if( m_bDisposed || m_bInDispose )
185 0 : return;
186 0 : m_aDisposeEventListeners.removeInterface( xListener );
187 : }
188 :
189 :
190 : // XPropertySet
191 :
192 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ChineseTranslation_UnoDialog::getPropertySetInfo( ) throw (uno::RuntimeException, std::exception)
193 : {
194 0 : return 0;
195 : }
196 0 : void SAL_CALL ChineseTranslation_UnoDialog::setPropertyValue( const OUString&, const uno::Any& ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
197 : {
198 : //only read only properties
199 0 : throw beans::PropertyVetoException();
200 : }
201 0 : uno::Any SAL_CALL ChineseTranslation_UnoDialog::getPropertyValue( const OUString& rPropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
202 : {
203 0 : uno::Any aRet;
204 :
205 0 : bool bDirectionToSimplified = true;
206 0 : bool bUseCharacterVariants = false;
207 0 : bool bTranslateCommonTerms = false;
208 :
209 : {
210 0 : SolarMutexGuard aSolarGuard;
211 0 : if( m_bDisposed || m_bInDispose || !m_pDialog )
212 0 : return aRet;
213 0 : m_pDialog->getSettings( bDirectionToSimplified, bTranslateCommonTerms );
214 : }
215 :
216 0 : if( rPropertyName.equals( "IsDirectionToSimplified" ) )
217 : {
218 0 : aRet <<= bDirectionToSimplified;
219 : }
220 0 : else if( rPropertyName.equals( "IsUseCharacterVariants" ) )
221 : {
222 0 : aRet <<= bUseCharacterVariants;
223 : }
224 0 : else if( rPropertyName.equals( "IsTranslateCommonTerms" ) )
225 : {
226 0 : aRet <<= bTranslateCommonTerms;
227 : }
228 : else
229 : {
230 0 : throw beans::UnknownPropertyException();
231 : }
232 0 : return aRet;
233 :
234 : }
235 0 : void SAL_CALL ChineseTranslation_UnoDialog::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
236 : {
237 : //only not bound properties -> ignore listener
238 0 : }
239 0 : void SAL_CALL ChineseTranslation_UnoDialog::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
240 : {
241 : //only not bound properties -> ignore listener
242 0 : }
243 0 : void SAL_CALL ChineseTranslation_UnoDialog::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
244 : {
245 : //only not bound properties -> ignore listener
246 0 : }
247 0 : void SAL_CALL ChineseTranslation_UnoDialog::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
248 : {
249 : //only not bound properties -> ignore listener
250 0 : }
251 :
252 :
253 0 : } //end namespace
254 :
255 :
256 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|