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