Get the style color and number just once
[LibreOffice.git] / svtools / source / uno / addrtempuno.cxx
blob0c8694e76b767d83160a07b2555cb3e197bbf4ad
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 .
20 #include <svtools/addresstemplate.hxx>
21 #include <svtools/genericunodialog.hxx>
22 #include <comphelper/proparrhlp.hxx>
23 #include <comphelper/propertysequence.hxx>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/util/AliasProgrammaticPair.hpp>
27 #include <com/sun/star/sdbc/XDataSource.hpp>
28 #include <vcl/svapp.hxx>
30 using namespace svt;
32 namespace {
34 #define UNODIALOG_PROPERTY_ID_ALIASES 100
35 constexpr OUStringLiteral UNODIALOG_PROPERTY_ALIASES = u"FieldMapping";
37 using namespace css::uno;
38 using namespace css::util;
39 using namespace css::beans;
40 using namespace css::sdbc;
42 class OAddressBookSourceDialogUno
43 :public OGenericUnoDialog
44 ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
46 private:
47 Sequence< AliasProgrammaticPair > m_aAliases;
48 Reference< XDataSource > m_xDataSource;
49 OUString m_sDataSourceName;
50 OUString m_sTable;
52 public:
53 explicit OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB);
55 // XTypeProvider
56 virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) override;
58 // XServiceInfo
59 virtual OUString SAL_CALL getImplementationName() override;
60 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
62 // XPropertySet
63 virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
64 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
66 // OPropertyArrayUsageHelper
67 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
69 virtual void SAL_CALL initialize(const Sequence< Any >& aArguments) override;
71 protected:
72 // OGenericUnoDialog overridables
73 virtual std::unique_ptr<weld::DialogController> createDialog(const css::uno::Reference<css::awt::XWindow>& rParent) override;
75 virtual void implInitialize(const css::uno::Any& _rValue) override;
77 virtual void executedDialog(sal_Int16 _nExecutionResult) override;
81 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB)
82 :OGenericUnoDialog(_rxORB)
84 registerProperty(UNODIALOG_PROPERTY_ALIASES, UNODIALOG_PROPERTY_ID_ALIASES, PropertyAttribute::READONLY,
85 &m_aAliases, cppu::UnoType<decltype(m_aAliases)>::get());
89 Sequence<sal_Int8> SAL_CALL OAddressBookSourceDialogUno::getImplementationId( )
91 return css::uno::Sequence<sal_Int8>();
95 OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName()
97 return u"com.sun.star.comp.svtools.OAddressBookSourceDialogUno"_ustr;
101 css::uno::Sequence<OUString> SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames()
103 return { u"com.sun.star.ui.AddressBookSourceDialog"_ustr };
107 Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo()
109 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
110 return xInfo;
113 ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
115 return *getArrayHelper();
118 ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
120 Sequence< Property > aProps;
121 describeProperties(aProps);
122 return new ::cppu::OPropertyArrayHelper(aProps);
125 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
127 OGenericUnoDialog::executedDialog(_nExecutionResult);
129 if ( _nExecutionResult && m_xDialog )
130 static_cast<AddressBookSourceDialog*>(m_xDialog.get())->getFieldMapping(m_aAliases);
133 void SAL_CALL OAddressBookSourceDialogUno::initialize(const Sequence< Any >& rArguments)
135 if( rArguments.getLength() == 5 )
137 Reference<css::awt::XWindow> xParentWindow;
138 Reference<css::beans::XPropertySet> xDataSource;
139 OUString sDataSourceName;
140 OUString sCommand;
141 OUString sTitle;
142 if ( (rArguments[0] >>= xParentWindow)
143 && (rArguments[1] >>= xDataSource)
144 && (rArguments[2] >>= sDataSourceName)
145 && (rArguments[3] >>= sCommand)
146 && (rArguments[4] >>= sTitle) )
149 // convert the parameters for creating the dialog to PropertyValues
150 Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
152 {"ParentWindow", Any(xParentWindow)},
153 {"DataSource", Any(xDataSource)},
154 {"DataSourceName", Any(sDataSourceName)},
155 {"Command", Any(sCommand)}, // the table to use
156 {"Title", Any(sTitle)}
157 }));
158 OGenericUnoDialog::initialize(aArguments);
159 return;
162 OGenericUnoDialog::initialize(rArguments);
165 void OAddressBookSourceDialogUno::implInitialize(const css::uno::Any& _rValue)
167 PropertyValue aVal;
168 if (_rValue >>= aVal)
170 if (aVal.Name == "DataSource")
172 bool bSuccess = aVal.Value >>= m_xDataSource;
173 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
174 return;
177 if (aVal.Name == "DataSourceName")
179 bool bSuccess = aVal.Value >>= m_sDataSourceName;
180 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
181 return;
184 if (aVal.Name == "Command")
186 bool bSuccess = aVal.Value >>= m_sTable;
187 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
188 return;
192 OGenericUnoDialog::implInitialize( _rValue );
195 std::unique_ptr<weld::DialogController> OAddressBookSourceDialogUno::createDialog(const css::uno::Reference<css::awt::XWindow>& rParent)
197 weld::Window* pParent = Application::GetFrameWeld(rParent);
198 if ( m_xDataSource.is() && !m_sTable.isEmpty() )
199 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext, m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases);
200 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext);
204 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
205 com_sun_star_comp_svtools_OAddressBookSourceDialogUno_get_implementation(
206 css::uno::XComponentContext * context,
207 css::uno::Sequence<css::uno::Any> const &)
209 return cppu::acquire(new OAddressBookSourceDialogUno(context));
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */