tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / model / main / DataTable.cxx
blob01aa023ed9772acc569d46250193300bc36e5327
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/.
8 */
10 #include <DataTable.hxx>
12 #include <LinePropertiesHelper.hxx>
13 #include <FillProperties.hxx>
14 #include <CharacterProperties.hxx>
15 #include <ModifyListenerHelper.hxx>
16 #include <PropertyHelper.hxx>
17 #include <cppuhelper/supportsservice.hxx>
19 #include <com/sun/star/beans/PropertyAttribute.hpp>
20 #include <com/sun/star/uno/XComponentContext.hpp>
21 #include <com/sun/star/drawing/FillStyle.hpp>
23 #include <algorithm>
25 using namespace css;
27 namespace
29 /** DataTable Properties */
30 enum
32 DataTableProperty_HorizontalBorder,
33 DataTableProperty_VerticalBorder,
34 DataTableProperty_Outilne,
35 DataTableProperty_Keys,
38 void lcl_AddPropertiesToVector(std::vector<beans::Property>& rProps)
40 auto const nBound = beans::PropertyAttribute::BOUND;
41 auto const nMaybeDefault = beans::PropertyAttribute::MAYBEDEFAULT;
43 rProps.emplace_back("HBorder", DataTableProperty_HorizontalBorder, cppu::UnoType<bool>::get(),
44 nBound | nMaybeDefault);
45 rProps.emplace_back("VBorder", DataTableProperty_VerticalBorder, cppu::UnoType<bool>::get(),
46 nBound | nMaybeDefault);
47 rProps.emplace_back("Outline", DataTableProperty_Outilne, cppu::UnoType<bool>::get(),
48 nBound | nMaybeDefault);
49 rProps.emplace_back("Keys", DataTableProperty_Keys, cppu::UnoType<bool>::get(),
50 nBound | nMaybeDefault);
53 const ::chart::tPropertyValueMap& StaticDataTableDefaults()
55 static ::chart::tPropertyValueMap aStaticDefaults = []() {
56 ::chart::tPropertyValueMap aMap;
57 ::chart::LinePropertiesHelper::AddDefaultsToMap(aMap);
58 ::chart::FillProperties::AddDefaultsToMap(aMap);
59 ::chart::CharacterProperties::AddDefaultsToMap(aMap);
61 ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_HorizontalBorder,
62 false);
63 ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_VerticalBorder,
64 false);
65 ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_Outilne, false);
66 ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_Keys, false);
68 ::chart::PropertyHelper::setPropertyValue(
69 aMap, ::chart::LinePropertiesHelper::PROP_LINE_WIDTH, uno::Any(sal_Int32(1)));
71 ::chart::PropertyHelper::setPropertyValueDefault(
72 aMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE);
74 float fDefaultCharHeight = 10.0;
75 ::chart::PropertyHelper::setPropertyValue(
76 aMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight);
77 ::chart::PropertyHelper::setPropertyValue(
78 aMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight);
79 ::chart::PropertyHelper::setPropertyValue(
80 aMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight);
81 return aMap;
82 }();
83 return aStaticDefaults;
86 cppu::OPropertyArrayHelper& StaticDataTableInfoHelper()
88 static cppu::OPropertyArrayHelper aPropHelper = []() {
89 std::vector<beans::Property> aProperties;
90 lcl_AddPropertiesToVector(aProperties);
91 ::chart::LinePropertiesHelper::AddPropertiesToVector(aProperties);
92 ::chart::FillProperties::AddPropertiesToVector(aProperties);
93 ::chart::CharacterProperties::AddPropertiesToVector(aProperties);
94 std::sort(aProperties.begin(), aProperties.end(), ::chart::PropertyNameLess());
96 return comphelper::containerToSequence(aProperties);
97 }();
98 return aPropHelper;
101 } // anonymous namespace
103 namespace chart
105 DataTable::DataTable()
106 : m_xModifyEventForwarder(new ModifyEventForwarder())
110 DataTable::DataTable(const DataTable& rOther)
111 : DataTable_Base(rOther)
112 , ::property::OPropertySet(rOther)
113 , m_xModifyEventForwarder(new ModifyEventForwarder())
117 DataTable::~DataTable() = default;
119 // ____ XCloneable ____
120 uno::Reference<util::XCloneable> SAL_CALL DataTable::createClone()
122 return uno::Reference<util::XCloneable>(new DataTable(*this));
125 // ____ XModifyBroadcaster ____
126 void SAL_CALL DataTable::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
128 m_xModifyEventForwarder->addModifyListener(aListener);
131 void SAL_CALL
132 DataTable::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
134 m_xModifyEventForwarder->removeModifyListener(aListener);
137 // ____ XModifyListener ____
138 void SAL_CALL DataTable::modified(const lang::EventObject& aEvent)
140 m_xModifyEventForwarder->modified(aEvent);
143 // ____ XEventListener (base of XModifyListener) ____
144 void SAL_CALL DataTable::disposing(const lang::EventObject& /* Source */)
146 // nothing
149 // ____ OPropertySet ____
150 void DataTable::firePropertyChangeEvent()
152 m_xModifyEventForwarder->modified(lang::EventObject(static_cast<uno::XWeak*>(this)));
155 // ____ OPropertySet ____
156 void DataTable::GetDefaultValue(sal_Int32 nHandle, uno::Any& rAny) const
158 const tPropertyValueMap& rStaticDefaults = StaticDataTableDefaults();
159 auto aFound = rStaticDefaults.find(nHandle);
160 if (aFound == rStaticDefaults.end())
161 rAny.clear();
162 else
163 rAny = (*aFound).second;
166 ::cppu::IPropertyArrayHelper& SAL_CALL DataTable::getInfoHelper()
168 return StaticDataTableInfoHelper();
171 // ____ XPropertySet ____
172 uno::Reference<beans::XPropertySetInfo> SAL_CALL DataTable::getPropertySetInfo()
174 static uno::Reference<beans::XPropertySetInfo> xPropertySetInfo(
175 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticDataTableInfoHelper()));
176 return xPropertySetInfo;
179 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
180 OUString SAL_CALL DataTable::getImplementationName()
182 return u"com.sun.star.comp.chart2.DataTable"_ustr;
185 sal_Bool SAL_CALL DataTable::supportsService(const OUString& rServiceName)
187 return cppu::supportsService(this, rServiceName);
190 uno::Sequence<OUString> SAL_CALL DataTable::getSupportedServiceNames()
192 return { u"com.sun.star.chart2.DataTable"_ustr, u"com.sun.star.beans.PropertySet"_ustr,
193 u"com.sun.star.drawing.FillProperties"_ustr,
194 u"com.sun.star.drawing.LineProperties"_ustr,
195 u"com.sun.star.style.CharacterProperties"_ustr };
198 IMPLEMENT_FORWARD_XINTERFACE2(DataTable, DataTable_Base, ::property::OPropertySet)
199 IMPLEMENT_FORWARD_XTYPEPROVIDER2(DataTable, DataTable_Base, ::property::OPropertySet)
201 } // namespace chart
203 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
204 com_sun_star_comp_chart2_DataTable_get_implementation(
205 css::uno::XComponentContext* /*pComponentContext*/, uno::Sequence<uno::Any> const& /*rAny*/)
207 return cppu::acquire(new ::chart::DataTable);
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */