GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / uno / genericunodialog.cxx
blob2e821bf42937829d294db440b212e1db10ec99c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "svtools/genericunodialog.hxx"
23 #include <com/sun/star/beans/NamedValue.hpp>
24 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 #include <toolkit/awt/vclxwindow.hxx>
27 #include <comphelper/extract.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <comphelper/property.hxx>
31 #include <osl/diagnose.h>
32 #include <tools/diagnose_ex.h>
33 #include <vcl/msgbox.hxx>
34 #include <osl/mutex.hxx>
35 #include <vcl/svapp.hxx>
37 using namespace ::comphelper;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::ucb;
43 //.........................................................................
44 namespace svt
46 //.........................................................................
48 //-------------------------------------------------------------------------
49 OGenericUnoDialog::OGenericUnoDialog(const Reference< XComponentContext >& _rxContext)
50 :OPropertyContainer(GetBroadcastHelper())
51 ,m_pDialog(NULL)
52 ,m_bExecuting(sal_False)
53 ,m_bCanceled(sal_False)
54 ,m_bTitleAmbiguous(sal_True)
55 ,m_bInitialized( false )
56 ,m_bNeedInitialization( false )
57 ,m_aContext(_rxContext)
59 registerProperty(OUString(UNODIALOG_PROPERTY_TITLE), UNODIALOG_PROPERTY_ID_TITLE, PropertyAttribute::TRANSIENT,
60 &m_sTitle, getCppuType(&m_sTitle));
61 registerProperty(OUString(UNODIALOG_PROPERTY_PARENT), UNODIALOG_PROPERTY_ID_PARENT, PropertyAttribute::TRANSIENT,
62 &m_xParent, getCppuType(&m_xParent));
65 //-------------------------------------------------------------------------
66 OGenericUnoDialog::~OGenericUnoDialog()
68 if ( m_pDialog )
70 SolarMutexGuard aSolarGuard;
71 ::osl::MutexGuard aGuard( m_aMutex );
72 if ( m_pDialog )
73 destroyDialog();
77 //-------------------------------------------------------------------------
78 Any SAL_CALL OGenericUnoDialog::queryInterface(const Type& _rType) throw (RuntimeException)
80 Any aReturn = OGenericUnoDialogBase::queryInterface(_rType);
82 if (!aReturn.hasValue())
83 aReturn = ::cppu::queryInterface(_rType
84 ,static_cast<XPropertySet*>(this)
85 ,static_cast<XMultiPropertySet*>(this)
86 ,static_cast<XFastPropertySet*>(this)
89 return aReturn;
92 //-------------------------------------------------------------------------
93 Sequence<Type> SAL_CALL OGenericUnoDialog::getTypes( ) throw(RuntimeException)
95 return ::comphelper::concatSequences(
96 OGenericUnoDialogBase::getTypes(),
97 ::comphelper::OPropertyContainer::getTypes()
101 sal_Bool SAL_CALL OGenericUnoDialog::supportsService(const OUString& ServiceName) throw(RuntimeException)
103 return cppu::supportsService(this, ServiceName);
106 //-------------------------------------------------------------------------
107 void OGenericUnoDialog::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw(Exception)
109 // TODO : need some handling if we're currently executing ...
111 OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, rValue);
113 if (UNODIALOG_PROPERTY_ID_TITLE == nHandle)
115 // from now on m_sTitle is valid
116 m_bTitleAmbiguous = sal_False;
118 if (m_pDialog)
119 m_pDialog->SetText(m_sTitle);
123 //-------------------------------------------------------------------------
124 sal_Bool OGenericUnoDialog::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue) throw(IllegalArgumentException)
126 switch (nHandle)
128 case UNODIALOG_PROPERTY_ID_PARENT:
130 Reference<starawt::XWindow> xNew;
131 ::cppu::extractInterface(xNew, rValue);
132 if (xNew != m_xParent)
134 rConvertedValue <<= xNew;
135 rOldValue <<= m_xParent;
136 return sal_True;
138 return sal_False;
141 return OPropertyContainer::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
144 //-------------------------------------------------------------------------
145 void SAL_CALL OGenericUnoDialog::setTitle( const OUString& _rTitle ) throw(RuntimeException)
147 UnoDialogEntryGuard aGuard( *this );
151 setPropertyValue(OUString(UNODIALOG_PROPERTY_TITLE), makeAny(_rTitle));
153 catch(RuntimeException&)
155 // allowed to pass
156 throw;
158 catch( const Exception& )
160 DBG_UNHANDLED_EXCEPTION();
161 // not allowed to pass
165 //-------------------------------------------------------------------------
166 bool OGenericUnoDialog::impl_ensureDialog_lck()
168 if ( m_pDialog )
169 return true;
171 // get the parameters for the dialog from the current settings
173 // the parent window
174 Window* pParent = NULL;
175 VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParent);
176 if (pImplementation)
177 pParent = pImplementation->GetWindow();
179 // the title
180 OUString sTitle = m_sTitle;
182 Dialog* pDialog = createDialog( pParent );
183 OSL_ENSURE( pDialog, "OGenericUnoDialog::impl_ensureDialog_lck: createDialog returned nonsense!" );
184 if ( !pDialog )
185 return false;
187 // do some initialisations
188 if ( !m_bTitleAmbiguous )
189 pDialog->SetText( sTitle );
191 // be notified when the dialog is killed by somebody else
192 // #i65958# / 2006-07-07 / frank.schoenheit@sun.com
193 pDialog->AddEventListener( LINK( this, OGenericUnoDialog, OnDialogDying ) );
195 m_pDialog = pDialog;
197 return true;
200 //-------------------------------------------------------------------------
201 sal_Int16 SAL_CALL OGenericUnoDialog::execute( ) throw(RuntimeException)
203 // both creation and execution of the dialog must be guarded with the SolarMutex, so be generous here
204 SolarMutexGuard aSolarGuard;
206 Dialog* pDialogToExecute = NULL;
207 // create the dialog, if necessary
209 UnoDialogEntryGuard aGuard( *this );
211 if (m_bExecuting)
212 throw RuntimeException(
213 OUString( "already executing the dialog (recursive call)" ),
214 *this
217 m_bCanceled = sal_False;
218 m_bExecuting = sal_True;
220 if ( !impl_ensureDialog_lck() )
221 return 0;
223 pDialogToExecute = m_pDialog;
226 // start execution
227 sal_Int16 nReturn(0);
228 if ( pDialogToExecute )
229 nReturn = pDialogToExecute->Execute();
232 ::osl::MutexGuard aExecutionGuard(m_aExecutionMutex);
233 if (m_bCanceled)
234 nReturn = RET_CANCEL;
238 ::osl::MutexGuard aGuard(m_aMutex);
240 // get the settings of the dialog
241 executedDialog( nReturn );
243 m_bExecuting = sal_False;
246 // outta here
247 return nReturn;
250 #ifdef AWT_DIALOG
251 //-------------------------------------------------------------------------
252 void SAL_CALL OGenericUnoDialog::endExecute( ) throw(RuntimeException)
254 UnoDialogEntryGuard aGuard( *this );
255 if (!m_bExecuting)
256 throw RuntimeException();
259 ::osl::MutexGuard aExecutionGuard(m_aExecutionMutex);
260 OSL_ENSURE(m_pDialog, "OGenericUnoDialog::endExecute : executing which dialog ?");
261 // m_bExecuting is true but we have no dialog ?
262 if (!m_pDialog)
263 throw RuntimeException();
265 if (!m_pDialog->IsInExecute())
266 // we tighly missed it ... another thread finished the execution of the dialog,
267 // but did not manage it to reset m_bExecuting, it currently tries to acquire
268 // m_aMutex or m_aExecutionMutex
269 // => nothing to do
270 return;
272 m_pDialog->EndDialog(RET_CANCEL);
273 m_bCanceled = sal_True;
276 #endif
278 //-------------------------------------------------------------------------
279 void OGenericUnoDialog::implInitialize(const Any& _rValue)
283 PropertyValue aProperty;
284 NamedValue aValue;
285 if ( _rValue >>= aProperty )
287 setPropertyValue( aProperty.Name, aProperty.Value );
289 else if ( _rValue >>= aValue )
291 setPropertyValue( aValue.Name, aValue.Value );
294 catch(const Exception&)
296 DBG_UNHANDLED_EXCEPTION();
300 //-------------------------------------------------------------------------
301 void SAL_CALL OGenericUnoDialog::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
303 ::osl::MutexGuard aGuard( m_aMutex );
304 if ( m_bInitialized )
305 throw AlreadyInitializedException( OUString(), *this );
307 const Any* pArguments = aArguments.getConstArray();
308 for (sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
309 implInitialize(*pArguments);
311 m_bInitialized = true;
314 //-------------------------------------------------------------------------
315 void OGenericUnoDialog::destroyDialog()
317 delete m_pDialog;
318 m_pDialog = NULL;
321 //-------------------------------------------------------------------------
322 IMPL_LINK( OGenericUnoDialog, OnDialogDying, VclWindowEvent*, _pEvent )
324 OSL_ENSURE( _pEvent->GetWindow() == m_pDialog, "OGenericUnoDialog::OnDialogDying: where does this come from?" );
325 if ( _pEvent->GetId() == VCLEVENT_OBJECT_DYING )
326 m_pDialog = NULL;
327 return 0L;
330 //.........................................................................
331 } // namespace svt
332 //.........................................................................
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */