LibreOffice Module svtools (master) 1
genericunodialog.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/awt/XWindow.hpp>
23#include <com/sun/star/beans/NamedValue.hpp>
24#include <com/sun/star/beans/PropertyValue.hpp>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
27
30#include <osl/diagnose.h>
32#include <osl/mutex.hxx>
33#include <vcl/svapp.hxx>
34
35using namespace css::uno;
36using namespace css::lang;
37using namespace css::beans;
38using namespace css::ucb;
39
40
41namespace svt
42{
43
44
46 :OPropertyContainer(GetBroadcastHelper())
47 ,m_bExecuting(false)
48 ,m_bTitleAmbiguous(true)
49 ,m_bInitialized( false )
50 ,m_aContext(_rxContext)
51{
53 &m_sTitle, cppu::UnoType<decltype(m_sTitle)>::get());
55 &m_xParent, cppu::UnoType<decltype(m_xParent)>::get());
56}
57
58
60{
61 if (m_xDialog)
62 {
63 SolarMutexGuard aSolarGuard;
64 ::osl::MutexGuard aGuard( m_aMutex );
65 if (m_xDialog)
67 }
68}
69
70
72{
73 Any aReturn = OGenericUnoDialogBase::queryInterface(_rType);
74
75 if (!aReturn.hasValue())
76 aReturn = ::cppu::queryInterface(_rType
77 ,static_cast<XPropertySet*>(this)
78 ,static_cast<XMultiPropertySet*>(this)
79 ,static_cast<XFastPropertySet*>(this)
80 );
81
82 return aReturn;
83}
84
85
87{
88 return ::comphelper::concatSequences(
89 OGenericUnoDialogBase::getTypes(),
91 );
92}
93
94sal_Bool SAL_CALL OGenericUnoDialog::supportsService(const OUString& ServiceName)
95{
97}
98
99
100void OGenericUnoDialog::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue )
101{
102 // TODO: need some handling if we're currently executing ...
103
104 OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, rValue);
105
107 {
108 // from now on m_sTitle is valid
109 m_bTitleAmbiguous = false;
110
111 if (m_xDialog)
112 m_xDialog->set_title(m_sTitle);
113 }
114}
115
116
117sal_Bool OGenericUnoDialog::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
118{
119 switch (nHandle)
120 {
122 {
123 Reference<css::awt::XWindow> xNew(rValue, css::uno::UNO_QUERY);
124 if (xNew != m_xParent)
125 {
126 rConvertedValue <<= xNew;
127 rOldValue <<= m_xParent;
128 return true;
129 }
130 return false;
131 }
132 }
133 return OPropertyContainer::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
134}
135
136
137void SAL_CALL OGenericUnoDialog::setTitle( const OUString& _rTitle )
138{
139 UnoDialogEntryGuard aGuard( *this );
140
141 try
142 {
144 }
145 catch(RuntimeException&)
146 {
147 // allowed to pass
148 throw;
149 }
150 catch( const Exception& )
151 {
152 DBG_UNHANDLED_EXCEPTION("svtools.uno");
153 // not allowed to pass
154 }
155}
156
157
159{
160 if (m_xDialog)
161 return true;
162
163 // get the parameters for the dialog from the current settings
164
165 // the title
166 OUString sTitle = m_sTitle;
167
168 auto xDialog(createDialog(m_xParent));
169 OSL_ENSURE(xDialog, "OGenericUnoDialog::impl_ensureDialog_lck: createDialog returned nonsense!");
170 if (!xDialog)
171 return false;
172
173 // do some initialisations
175 xDialog->set_title(sTitle);
176
177 m_xDialog = std::move(xDialog);
178
179 return true;
180}
181
182sal_Int16 SAL_CALL OGenericUnoDialog::execute()
183{
184 // both creation and execution of the dialog must be guarded with the SolarMutex, so be generous here
185 SolarMutexGuard aSolarGuard;
186
187 // create the dialog, if necessary
188 {
189 UnoDialogEntryGuard aGuard( *this );
190
191 if (m_bExecuting)
192 throw RuntimeException(
193 "already executing the dialog (recursive call)",
194 *this
195 );
196
197 m_bExecuting = true;
198
199 if ( !impl_ensureDialog_lck() )
200 return 0;
201 }
202
203 // start execution
204 sal_Int16 nReturn(0);
205 if (m_xDialog)
206 nReturn = m_xDialog->run();
207
208 {
209 ::osl::MutexGuard aGuard(m_aMutex);
210
211 // get the settings of the dialog
212 executedDialog( nReturn );
213
214 m_bExecuting = false;
215 }
216
217 // outta here
218 return nReturn;
219}
220
221void OGenericUnoDialog::implInitialize(const Any& _rValue)
222{
223 try
224 {
225 PropertyValue aProperty;
226 NamedValue aValue;
227 if ( _rValue >>= aProperty )
228 {
229 setPropertyValue( aProperty.Name, aProperty.Value );
230 }
231 else if ( _rValue >>= aValue )
232 {
233 setPropertyValue( aValue.Name, aValue.Value );
234 }
235 }
236 catch(const Exception&)
237 {
238 DBG_UNHANDLED_EXCEPTION("svtools.uno");
239 }
240}
241
242void SAL_CALL OGenericUnoDialog::initialize( const Sequence< Any >& aArguments )
243{
244 ::osl::MutexGuard aGuard( m_aMutex );
245 if ( m_bInitialized )
246 throw AlreadyInitializedException( OUString(), *this );
247
248 for (const Any& rArgument : aArguments)
249 implInitialize(rArgument);
250
251 m_bInitialized = true;
252}
253
255{
256 SolarMutexGuard aSolarGuard;
257 m_xDialog.reset();
258}
259
260} // namespace svt
261
262
263/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
static css::uno::Sequence< css::uno::Type > getBaseTypes()
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
OGenericUnoDialog(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
bool impl_ensureDialog_lck()
ensures that m_pDialog is not <NULL>
std::unique_ptr< weld::DialogController > m_xDialog
virtual std::unique_ptr< weld::DialogController > createDialog(const css::uno::Reference< css::awt::XWindow > &rParent)=0
create the concrete dialog instance.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void executedDialog(sal_Int16)
called after the dialog has been executed
css::uno::Reference< css::awt::XWindow > m_xParent
title of the dialog
OUString m_sTitle
has "initialize" been called?
virtual void implInitialize(const css::uno::Any &_rValue)
smaller form of <method>initialize</method>.
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual ~OGenericUnoDialog() override
bool m_bExecuting
the dialog to execute
void destroyDialog()
called to destroy the dialog used. deletes m_pDialog and resets it to NULL
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &_rType) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool m_bInitialized
m_sTitle has not been set yet
virtual void SAL_CALL setTitle(const OUString &aTitle) override
virtual sal_Int16 SAL_CALL execute() override
bool m_bTitleAmbiguous
we're currently executing the dialog
helper class for guarding access to methods of an OGenericUnoDialog
Reference< XComponentContext > m_aContext
#define DBG_UNHANDLED_EXCEPTION(...)
#define UNODIALOG_PROPERTY_ID_TITLE
#define UNODIALOG_PROPERTY_ID_PARENT
Sequence< PropertyValue > aArguments
@ Exception
class SAL_NO_VTABLE XPropertySet
Type
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
constexpr OUStringLiteral UNODIALOG_PROPERTY_TITLE
constexpr OUStringLiteral UNODIALOG_PROPERTY_PARENT
sal_Int32 nHandle
unsigned char sal_Bool