Update git submodules
[LibreOffice.git] / reportdesign / source / ui / inspection / metadata.cxx
blobbfed5fb59d433c22ba41d3f629f454ca69623338
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 .
19 #include <metadata.hxx>
20 #include <com/sun/star/inspection/XPropertyHandler.hpp>
21 #include <core_resource.hxx>
22 #include <helpids.h>
23 #include <strings.hrc>
24 #include <strings.hxx>
26 #include <algorithm>
27 #include <string_view>
28 #include <utility>
30 namespace rptui
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star;
38 //= OPropertyInfoImpl
40 struct OPropertyInfoImpl
42 OUString sName;
43 OUString sTranslation;
44 OUString sHelpId;
45 sal_Int32 nId;
46 PropUIFlags nUIFlags;
48 OPropertyInfoImpl(
49 OUString aName,
50 sal_Int32 _nId,
51 OUString aTranslation,
52 OUString _sHelpId,
53 PropUIFlags _nUIFlags);
57 OPropertyInfoImpl::OPropertyInfoImpl(OUString _aName, sal_Int32 _nId,
58 OUString aString, OUString sHid, PropUIFlags _nUIFlags)
59 :sName(std::move(_aName))
60 ,sTranslation(std::move(aString))
61 ,sHelpId(std::move(sHid))
62 ,nId(_nId)
63 ,nUIFlags(_nUIFlags)
67 namespace {
69 // compare PropertyInfo
70 struct PropertyInfoLessByName
72 bool operator()( const OPropertyInfoImpl& _lhs, const OPropertyInfoImpl& _rhs )
74 return _lhs.sName < _rhs.sName;
80 //= OPropertyInfoService
82 sal_uInt16 OPropertyInfoService::s_nCount = 0;
83 OPropertyInfoImpl* OPropertyInfoService::s_pPropertyInfos = nullptr;
85 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo()
87 if ( s_pPropertyInfos )
88 return s_pPropertyInfos;
90 static OPropertyInfoImpl aPropertyInfos[] =
92 OPropertyInfoImpl(PROPERTY_FORCENEWPAGE, PROPERTY_ID_FORCENEWPAGE, RptResId(RID_STR_FORCENEWPAGE), HID_RPT_PROP_FORCENEWPAGE, PropUIFlags::Composeable),
93 OPropertyInfoImpl(PROPERTY_NEWROWORCOL, PROPERTY_ID_NEWROWORCOL, RptResId(RID_STR_NEWROWORCOL), HID_RPT_PROP_NEWROWORCOL, PropUIFlags::Composeable),
94 OPropertyInfoImpl(PROPERTY_KEEPTOGETHER, PROPERTY_ID_KEEPTOGETHER, RptResId(RID_STR_KEEPTOGETHER), HID_RPT_PROP_KEEPTOGETHER, PropUIFlags::Composeable),
95 OPropertyInfoImpl(PROPERTY_CANGROW, PROPERTY_ID_CANGROW, RptResId(RID_STR_CANGROW), HID_RPT_PROP_CANGROW, PropUIFlags::Composeable),
96 OPropertyInfoImpl(PROPERTY_CANSHRINK, PROPERTY_ID_CANSHRINK, RptResId(RID_STR_CANSHRINK), HID_RPT_PROP_CANSHRINK, PropUIFlags::Composeable),
97 OPropertyInfoImpl(PROPERTY_REPEATSECTION, PROPERTY_ID_REPEATSECTION, RptResId(RID_STR_REPEATSECTION), HID_RPT_PROP_REPEATSECTION, PropUIFlags::Composeable),
98 OPropertyInfoImpl(PROPERTY_PRINTREPEATEDVALUES, PROPERTY_ID_PRINTREPEATEDVALUES, RptResId(RID_STR_PRINTREPEATEDVALUES), HID_RPT_PROP_PRINTREPEATEDVALUES, PropUIFlags::Composeable),
99 OPropertyInfoImpl(PROPERTY_CONDITIONALPRINTEXPRESSION, PROPERTY_ID_CONDITIONALPRINTEXPRESSION, RptResId(RID_STR_CONDITIONALPRINTEXPRESSION), HID_RPT_PROP_CONDITIONALPRINTEXPRESSION,
100 PropUIFlags::Composeable ),
101 OPropertyInfoImpl(PROPERTY_STARTNEWCOLUMN, PROPERTY_ID_STARTNEWCOLUMN, RptResId(RID_STR_STARTNEWCOLUMN), HID_RPT_PROP_STARTNEWCOLUMN, PropUIFlags::Composeable),
102 OPropertyInfoImpl(PROPERTY_RESETPAGENUMBER, PROPERTY_ID_RESETPAGENUMBER, RptResId(RID_STR_RESETPAGENUMBER), HID_RPT_PROP_RESETPAGENUMBER, PropUIFlags::Composeable),
103 OPropertyInfoImpl(PROPERTY_PRINTWHENGROUPCHANGE, PROPERTY_ID_PRINTWHENGROUPCHANGE, RptResId(RID_STR_PRINTWHENGROUPCHANGE), HID_RPT_PROP_PRINTWHENGROUPCHANGE, PropUIFlags::Composeable),
104 OPropertyInfoImpl(PROPERTY_VISIBLE, PROPERTY_ID_VISIBLE, RptResId(RID_STR_VISIBLE), HID_RPT_PROP_VISIBLE, PropUIFlags::Composeable),
105 OPropertyInfoImpl(PROPERTY_GROUPKEEPTOGETHER, PROPERTY_ID_GROUPKEEPTOGETHER, RptResId(RID_STR_GROUPKEEPTOGETHER), HID_RPT_PROP_GROUPKEEPTOGETHER, PropUIFlags::Composeable),
106 OPropertyInfoImpl(PROPERTY_PAGEHEADEROPTION, PROPERTY_ID_PAGEHEADEROPTION, RptResId(RID_STR_PAGEHEADEROPTION), HID_RPT_PROP_PAGEHEADEROPTION, PropUIFlags::Composeable),
107 OPropertyInfoImpl(PROPERTY_PAGEFOOTEROPTION, PROPERTY_ID_PAGEFOOTEROPTION, RptResId(RID_STR_PAGEFOOTEROPTION), HID_RPT_PROP_PAGEFOOTEROPTION, PropUIFlags::Composeable),
108 OPropertyInfoImpl(PROPERTY_POSITIONX, PROPERTY_ID_POSITIONX, RptResId(RID_STR_POSITIONX), HID_RPT_PROP_RPT_POSITIONX, PropUIFlags::Composeable),
109 OPropertyInfoImpl(PROPERTY_POSITIONY, PROPERTY_ID_POSITIONY, RptResId(RID_STR_POSITIONY), HID_RPT_PROP_RPT_POSITIONY, PropUIFlags::Composeable),
110 OPropertyInfoImpl(PROPERTY_WIDTH, PROPERTY_ID_WIDTH, RptResId(RID_STR_WIDTH), HID_RPT_PROP_RPT_WIDTH, PropUIFlags::Composeable),
111 OPropertyInfoImpl(PROPERTY_HEIGHT, PROPERTY_ID_HEIGHT, RptResId(RID_STR_HEIGHT), HID_RPT_PROP_RPT_HEIGHT, PropUIFlags::Composeable),
112 OPropertyInfoImpl(PROPERTY_AUTOGROW, PROPERTY_ID_AUTOGROW, RptResId(RID_STR_AUTOGROW), HID_RPT_PROP_RPT_AUTOGROW, PropUIFlags::Composeable),
113 OPropertyInfoImpl(PROPERTY_FONT, PROPERTY_ID_FONT, RptResId(RID_STR_FONT), HID_RPT_PROP_RPT_FONT, PropUIFlags::Composeable),
114 OPropertyInfoImpl(PROPERTY_PREEVALUATED, PROPERTY_ID_PREEVALUATED, RptResId(RID_STR_PREEVALUATED), HID_RPT_PROP_PREEVALUATED, PropUIFlags::Composeable),
115 OPropertyInfoImpl(PROPERTY_DEEPTRAVERSING, PROPERTY_ID_DEEPTRAVERSING, RptResId(RID_STR_DEEPTRAVERSING), HID_RPT_PROP_DEEPTRAVERSING, PropUIFlags::Composeable),
116 OPropertyInfoImpl(PROPERTY_FORMULA, PROPERTY_ID_FORMULA, RptResId(RID_STR_FORMULA), HID_RPT_PROP_FORMULA, PropUIFlags::Composeable),
117 OPropertyInfoImpl(PROPERTY_INITIALFORMULA, PROPERTY_ID_INITIALFORMULA, RptResId(RID_STR_INITIALFORMULA), HID_RPT_PROP_INITIALFORMULA, PropUIFlags::Composeable),
118 OPropertyInfoImpl(PROPERTY_TYPE, PROPERTY_ID_TYPE, RptResId(RID_STR_TYPE), HID_RPT_PROP_TYPE, PropUIFlags::Composeable | PropUIFlags::DataProperty),
119 OPropertyInfoImpl(PROPERTY_DATAFIELD,PROPERTY_ID_DATAFIELD, RptResId(RID_STR_DATAFIELD), HID_RPT_PROP_DATAFIELD, PropUIFlags::Composeable | PropUIFlags::DataProperty),
120 OPropertyInfoImpl(PROPERTY_FORMULALIST, PROPERTY_ID_FORMULALIST, RptResId(RID_STR_FORMULALIST), HID_RPT_PROP_FORMULALIST, PropUIFlags::Composeable | PropUIFlags::DataProperty),
121 OPropertyInfoImpl(PROPERTY_SCOPE, PROPERTY_ID_SCOPE, RptResId(RID_STR_SCOPE), HID_RPT_PROP_SCOPE, PropUIFlags::Composeable | PropUIFlags::DataProperty),
122 OPropertyInfoImpl(PROPERTY_PRESERVEIRI, PROPERTY_ID_PRESERVEIRI, RptResId(RID_STR_PRESERVEIRI), HID_RPT_PROP_PRESERVEIRI, PropUIFlags::Composeable),
123 OPropertyInfoImpl(PROPERTY_BACKCOLOR, PROPERTY_ID_BACKCOLOR, RptResId(RID_STR_BACKCOLOR), HID_RPT_PROP_BACKCOLOR, PropUIFlags::Composeable),
124 OPropertyInfoImpl(PROPERTY_CONTROLBACKGROUND, PROPERTY_ID_CONTROLBACKGROUND, RptResId(RID_STR_BACKCOLOR), HID_RPT_PROP_BACKCOLOR, PropUIFlags::Composeable),
125 OPropertyInfoImpl(PROPERTY_BACKTRANSPARENT, PROPERTY_ID_BACKTRANSPARENT, RptResId(RID_STR_BACKTRANSPARENT), HID_RPT_PROP_BACKTRANSPARENT, PropUIFlags::Composeable),
126 OPropertyInfoImpl(PROPERTY_CONTROLBACKGROUNDTRANSPARENT, PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT, RptResId(RID_STR_CONTROLBACKGROUNDTRANSPARENT), HID_RPT_PROP_CONTROLBACKGROUNDTRANSPARENT,
127 PropUIFlags::Composeable),
128 OPropertyInfoImpl(PROPERTY_CHARTTYPE, PROPERTY_ID_CHARTTYPE, RptResId(RID_STR_CHARTTYPE), HID_RPT_PROP_CHARTTYPE, PropUIFlags::Composeable),
129 OPropertyInfoImpl(PROPERTY_PREVIEW_COUNT, PROPERTY_ID_PREVIEW_COUNT, RptResId(RID_STR_PREVIEW_COUNT), HID_RPT_PROP_PREVIEW_COUNT, PropUIFlags::Composeable),
130 OPropertyInfoImpl(PROPERTY_MASTERFIELDS, PROPERTY_ID_MASTERFIELDS, RptResId(RID_STR_MASTERFIELDS), HID_RPT_PROP_MASTERFIELDS, PropUIFlags::Composeable | PropUIFlags::DataProperty),
131 OPropertyInfoImpl(PROPERTY_DETAILFIELDS, PROPERTY_ID_DETAILFIELDS, RptResId(RID_STR_DETAILFIELDS), HID_RPT_PROP_DETAILFIELDS, PropUIFlags::Composeable | PropUIFlags::DataProperty),
132 OPropertyInfoImpl(PROPERTY_AREA, PROPERTY_ID_AREA, RptResId(RID_STR_AREA), HID_RPT_PROP_AREA, PropUIFlags::Composeable),
133 OPropertyInfoImpl(PROPERTY_MIMETYPE, PROPERTY_ID_MIMETYPE, RptResId(RID_STR_MIMETYPE), HID_RPT_PROP_MIMETYPE, PropUIFlags::Composeable | PropUIFlags::DataProperty),
134 OPropertyInfoImpl(PROPERTY_PARAADJUST, PROPERTY_ID_PARAADJUST, RptResId(RID_STR_PARAADJUST), HID_RPT_PROP_PARAADJUST, PropUIFlags::Composeable),
135 OPropertyInfoImpl(PROPERTY_VERTICALALIGN, PROPERTY_ID_VERTICALALIGN, RptResId(RID_STR_VERTICALALIGN), HID_RPT_PROP_VERTICALALIGN, PropUIFlags::Composeable)
138 s_pPropertyInfos = aPropertyInfos;
139 s_nCount = SAL_N_ELEMENTS(aPropertyInfos);
140 ::std::sort( aPropertyInfos, aPropertyInfos + SAL_N_ELEMENTS(aPropertyInfos), PropertyInfoLessByName() );
142 return s_pPropertyInfos;
146 sal_Int32 OPropertyInfoService::getPropertyId(const OUString& _rName)
148 const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName);
149 return pInfo ? pInfo->nId : -1;
153 OUString OPropertyInfoService::getPropertyTranslation(sal_Int32 _nId)
155 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
156 return pInfo ? pInfo->sTranslation : OUString();
160 OUString OPropertyInfoService::getPropertyHelpId(sal_Int32 _nId)
162 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
163 return pInfo ? pInfo->sHelpId : OUString();
167 PropUIFlags OPropertyInfoService::getPropertyUIFlags(sal_Int32 _nId)
169 const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
170 return pInfo ? pInfo->nUIFlags : PropUIFlags::NONE;
174 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(const OUString& _rName)
176 // initialization
177 if(!s_pPropertyInfos)
178 getPropertyInfo();
179 OPropertyInfoImpl aSearch(_rName, 0, OUString(), u""_ustr, PropUIFlags::NONE);
181 const OPropertyInfoImpl* pPropInfo = ::std::lower_bound(
182 s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() );
184 if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName )
185 return pPropInfo;
187 return nullptr;
191 const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(sal_Int32 _nId)
193 // initialization
194 if(!s_pPropertyInfos)
196 getPropertyInfo();
197 assert(s_pPropertyInfos);
200 // TODO: a real structure which allows quick access by name as well as by id
201 for (sal_uInt16 i = 0; i < s_nCount; i++)
202 if (s_pPropertyInfos[i].nId == _nId)
203 return &s_pPropertyInfos[i];
205 return nullptr;
209 bool OPropertyInfoService::isComposable( const OUString& _rPropertyName, const css::uno::Reference< css::inspection::XPropertyHandler >& _rxFormComponentHandler )
211 sal_Int32 nId = getPropertyId( _rPropertyName );
212 if ( nId != -1 )
214 PropUIFlags nFlags = getPropertyUIFlags( nId );
215 return bool( nFlags & PropUIFlags::Composeable );
218 return _rxFormComponentHandler->isComposable( _rPropertyName );
222 void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const css::uno::Reference< css::inspection::XPropertyHandler >& _xFormComponentHandler)
224 const uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties();
225 static const std::u16string_view pExcludeProperties[] =
227 u"Enabled",
228 u"Printable",
229 u"WordBreak",
230 u"MultiLine",
231 u"Tag",
232 u"HelpText",
233 u"HelpURL",
234 u"MaxTextLen",
235 u"ReadOnly",
236 u"Tabstop",
237 u"TabIndex",
238 u"ValueMin",
239 u"ValueMax",
240 u"Spin",
241 u"SpinValue",
242 u"SpinValueMin",
243 u"SpinValueMax",
244 u"DefaultSpinValue",
245 u"SpinIncrement",
246 u"Repeat",
247 u"RepeatDelay",
248 u"ControlLabel", /// TODO: has to be checked
249 u"LabelControl",
250 u"Title", // comment this out if you want to have title feature for charts
251 PROPERTY_MAXTEXTLEN,
252 PROPERTY_EFFECTIVEDEFAULT,
253 PROPERTY_EFFECTIVEMAX,
254 PROPERTY_EFFECTIVEMIN,
255 u"HideInactiveSelection",
256 u"SubmitAction",
257 u"InputRequired",
258 u"VerticalAlign",
259 PROPERTY_ALIGN,
260 PROPERTY_EMPTY_IS_NULL,
261 PROPERTY_FILTERPROPOSAL
262 ,PROPERTY_POSITIONX
263 ,PROPERTY_POSITIONY
264 ,PROPERTY_WIDTH
265 ,PROPERTY_HEIGHT
266 ,PROPERTY_AUTOGROW
267 ,PROPERTY_FONT
268 ,PROPERTY_LABEL
269 ,PROPERTY_LINECOLOR
270 ,PROPERTY_BORDER
271 ,PROPERTY_BORDERCOLOR
272 ,PROPERTY_BACKTRANSPARENT
273 ,PROPERTY_CONTROLBACKGROUND
274 ,PROPERTY_BACKGROUNDCOLOR
275 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
276 ,PROPERTY_FORMULALIST
277 ,PROPERTY_SCOPE
278 ,PROPERTY_TYPE
279 ,PROPERTY_DATASOURCENAME
280 ,PROPERTY_VERTICALALIGN
283 for (beans::Property const & prop : aProps)
285 size_t nPos = 0;
286 for (; nPos < SAL_N_ELEMENTS(pExcludeProperties) && pExcludeProperties[nPos] != prop.Name; ++nPos )
288 if ( nPos == SAL_N_ELEMENTS(pExcludeProperties) )
289 _rExcludeProperties.push_back(prop);
294 } // namespace pcr
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */