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