LibreOffice Module reportdesign (master)  1
metadata.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 #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>
25 
26 #include <algorithm>
27 #include <string_view>
28 
29 namespace rptui
30 {
31 
32 
33  using namespace ::com::sun::star::uno;
34  using namespace ::com::sun::star;
35 
36 
37  //= OPropertyInfoImpl
38 
40  {
41  OUString sName;
42  OUString sTranslation;
43  OString sHelpId;
44  sal_Int32 nId;
46 
48  const OUString& rName,
49  sal_Int32 _nId,
50  const OUString& aTranslation,
51  const OString& _sHelpId,
52  PropUIFlags _nUIFlags);
53  };
54 
55 
56  OPropertyInfoImpl::OPropertyInfoImpl(const OUString& _rName, sal_Int32 _nId,
57  const OUString& aString, const OString& sHid, PropUIFlags _nUIFlags)
58  :sName(_rName)
59  ,sTranslation(aString)
60  ,sHelpId(sHid)
61  ,nId(_nId)
62  ,nUIFlags(_nUIFlags)
63  {
64  }
65 
66  namespace {
67 
68  // compare PropertyInfo
69  struct PropertyInfoLessByName
70  {
71  bool operator()( const OPropertyInfoImpl& _lhs, const OPropertyInfoImpl& _rhs )
72  {
73  return _lhs.sName < _rhs.sName;
74  }
75  };
76 
77  }
78 
79  //= OPropertyInfoService
80 
81 #define DEF_INFO( ident, uinameres, helpid, flags ) \
82  OPropertyInfoImpl( PROPERTY_##ident, PROPERTY_ID_##ident, \
83  RptResId( RID_STR_##uinameres ), HID_RPT_PROP_##helpid, flags )
84 
85 #define DEF_INFO_1( ident, uinameres, helpid, flag1 ) \
86  DEF_INFO( ident, uinameres, helpid, PropUIFlags::flag1 )
87 
88 #define DEF_INFO_2( ident, uinameres, helpid, flag1, flag2 ) \
89  DEF_INFO( ident, uinameres, helpid, PropUIFlags::flag1 | PropUIFlags::flag2 )
90 
91  sal_uInt16 OPropertyInfoService::s_nCount = 0;
92  OPropertyInfoImpl* OPropertyInfoService::s_pPropertyInfos = nullptr;
93 
95  {
96  if ( s_pPropertyInfos )
97  return s_pPropertyInfos;
98 
99  static OPropertyInfoImpl aPropertyInfos[] =
100  {
101  /*
102  DEF_INFO_?( propname and id, resource id, help id, flags ),
103  */
104  DEF_INFO_1( FORCENEWPAGE, FORCENEWPAGE, FORCENEWPAGE, Composeable )
105  ,DEF_INFO_1( NEWROWORCOL, NEWROWORCOL, NEWROWORCOL, Composeable )
106  ,DEF_INFO_1( KEEPTOGETHER, KEEPTOGETHER, KEEPTOGETHER, Composeable )
107  ,DEF_INFO_1( CANGROW, CANGROW, CANGROW, Composeable )
108  ,DEF_INFO_1( CANSHRINK, CANSHRINK, CANSHRINK, Composeable )
109  ,DEF_INFO_1( REPEATSECTION, REPEATSECTION, REPEATSECTION, Composeable )
110  ,DEF_INFO_1( PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, PRINTREPEATEDVALUES, Composeable )
111  ,DEF_INFO_1( CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, Composeable )
112  ,DEF_INFO_1( STARTNEWCOLUMN, STARTNEWCOLUMN, STARTNEWCOLUMN, Composeable )
113  ,DEF_INFO_1( RESETPAGENUMBER, RESETPAGENUMBER, RESETPAGENUMBER, Composeable )
114  ,DEF_INFO_1( PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, PRINTWHENGROUPCHANGE, Composeable )
116  ,DEF_INFO_1( GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, GROUPKEEPTOGETHER, Composeable )
117  ,DEF_INFO_1( PAGEHEADEROPTION, PAGEHEADEROPTION, PAGEHEADEROPTION, Composeable )
118  ,DEF_INFO_1( PAGEFOOTEROPTION, PAGEFOOTEROPTION, PAGEFOOTEROPTION, Composeable )
119  ,DEF_INFO_1( POSITIONX, POSITIONX, RPT_POSITIONX, Composeable )
120  ,DEF_INFO_1( POSITIONY, POSITIONY, RPT_POSITIONY, Composeable )
121  ,DEF_INFO_1( WIDTH, WIDTH, RPT_WIDTH, Composeable )
122  ,DEF_INFO_1( HEIGHT, HEIGHT, RPT_HEIGHT, Composeable )
123  ,DEF_INFO_1( AUTOGROW, AUTOGROW, RPT_AUTOGROW, Composeable )
124  ,DEF_INFO_1( FONT, FONT, RPT_FONT, Composeable )
125  ,DEF_INFO_1( PREEVALUATED, PREEVALUATED, PREEVALUATED, Composeable )
126  ,DEF_INFO_1( DEEPTRAVERSING, DEEPTRAVERSING, DEEPTRAVERSING, Composeable )
128  ,DEF_INFO_1( INITIALFORMULA, INITIALFORMULA, INITIALFORMULA, Composeable )
131  ,DEF_INFO_2( FORMULALIST, FORMULALIST, FORMULALIST, Composeable,DataProperty )
132  ,DEF_INFO_2( SCOPE, SCOPE, SCOPE, Composeable,DataProperty )
133  ,DEF_INFO_1( PRESERVEIRI, PRESERVEIRI, PRESERVEIRI, Composeable )
135  ,DEF_INFO_1( CONTROLBACKGROUND, BACKCOLOR, BACKCOLOR, Composeable )
136  ,DEF_INFO_1( BACKTRANSPARENT, BACKTRANSPARENT, BACKTRANSPARENT, Composeable )
137  ,DEF_INFO_1( CONTROLBACKGROUNDTRANSPARENT, CONTROLBACKGROUNDTRANSPARENT,
138  CONTROLBACKGROUNDTRANSPARENT, Composeable )
139  ,DEF_INFO_1( CHARTTYPE, CHARTTYPE, CHARTTYPE, Composeable )
140  ,DEF_INFO_1( PREVIEW_COUNT, PREVIEW_COUNT, PREVIEW_COUNT, Composeable )
141  ,DEF_INFO_2( MASTERFIELDS, MASTERFIELDS, MASTERFIELDS, Composeable,DataProperty )
142  ,DEF_INFO_2( DETAILFIELDS, DETAILFIELDS, DETAILFIELDS, Composeable,DataProperty)
144  ,DEF_INFO_2( MIMETYPE, MIMETYPE, MIMETYPE, Composeable,DataProperty )
145  ,DEF_INFO_1( PARAADJUST, PARAADJUST, PARAADJUST, Composeable )
146  ,DEF_INFO_1( VERTICALALIGN, VERTICALALIGN, VERTICALALIGN, Composeable )
147  };
148 
149  s_pPropertyInfos = aPropertyInfos;
150  s_nCount = SAL_N_ELEMENTS(aPropertyInfos);
151  ::std::sort( aPropertyInfos, aPropertyInfos + SAL_N_ELEMENTS(aPropertyInfos), PropertyInfoLessByName() );
152 
153  return s_pPropertyInfos;
154  }
155 
156 
157  sal_Int32 OPropertyInfoService::getPropertyId(const OUString& _rName)
158  {
159  const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName);
160  return pInfo ? pInfo->nId : -1;
161  }
162 
163 
165  {
166  const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
167  return pInfo ? pInfo->sTranslation : OUString();
168  }
169 
170 
172  {
173  const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
174  return pInfo ? pInfo->sHelpId : OString();
175  }
176 
177 
179  {
180  const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
181  return pInfo ? pInfo->nUIFlags : PropUIFlags::NONE;
182  }
183 
184 
186  {
187  // initialization
188  if(!s_pPropertyInfos)
189  getPropertyInfo();
190  OPropertyInfoImpl aSearch(_rName, 0, OUString(), "", PropUIFlags::NONE);
191 
192  const OPropertyInfoImpl* pPropInfo = ::std::lower_bound(
193  s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() );
194 
195  if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName )
196  return pPropInfo;
197 
198  return nullptr;
199  }
200 
201 
203  {
204  // initialization
205  if(!s_pPropertyInfos)
206  getPropertyInfo();
207 
208  // TODO: a real structure which allows quick access by name as well as by id
209  for (sal_uInt16 i = 0; i < s_nCount; i++)
210  if (s_pPropertyInfos[i].nId == _nId)
211  return &s_pPropertyInfos[i];
212 
213  return nullptr;
214  }
215 
216 
217  bool OPropertyInfoService::isComposable( const OUString& _rPropertyName, const css::uno::Reference< css::inspection::XPropertyHandler >& _rxFormComponentHandler )
218  {
219  sal_Int32 nId = getPropertyId( _rPropertyName );
220  if ( nId != -1 )
221  {
222  PropUIFlags nFlags = getPropertyUIFlags( nId );
223  return bool( nFlags & PropUIFlags::Composeable );
224  }
225 
226  return _rxFormComponentHandler->isComposable( _rPropertyName );
227  }
228 
229 
230  void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const css::uno::Reference< css::inspection::XPropertyHandler >& _xFormComponentHandler)
231  {
232  const uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties();
233  static const std::u16string_view pExcludeProperties[] =
234  {
235  u"Enabled",
236  u"Printable",
237  u"WordBreak",
238  u"MultiLine",
239  u"Tag",
240  u"HelpText",
241  u"HelpURL",
242  u"MaxTextLen",
243  u"ReadOnly",
244  u"Tabstop",
245  u"TabIndex",
246  u"ValueMin",
247  u"ValueMax",
248  u"Spin",
249  u"SpinValue",
250  u"SpinValueMin",
251  u"SpinValueMax",
252  u"DefaultSpinValue",
253  u"SpinIncrement",
254  u"Repeat",
255  u"RepeatDelay",
256  u"ControlLabel",
257  u"LabelControl",
258  u"Title", // comment this out if you want to have title feature for charts
263  u"HideInactiveSelection",
264  u"SubmitAction",
265  u"InputRequired",
266  u"VerticalAlign",
267  u"" PROPERTY_ALIGN,
270  ,u"" PROPERTY_POSITIONX
271  ,u"" PROPERTY_POSITIONY
272  ,u"" PROPERTY_WIDTH
273  ,u"" PROPERTY_HEIGHT
274  ,u"" PROPERTY_AUTOGROW
275  ,u"" PROPERTY_FONT
276  ,u"" PROPERTY_LABEL
277  ,u"" PROPERTY_LINECOLOR
278  ,u"" PROPERTY_BORDER
285  ,u"" PROPERTY_SCOPE
286  ,u"" PROPERTY_TYPE
289  };
290 
291  for (beans::Property const & prop : aProps)
292  {
293  size_t nPos = 0;
294  for (; nPos < SAL_N_ELEMENTS(pExcludeProperties) && pExcludeProperties[nPos] != prop.Name; ++nPos )
295  ;
296  if ( nPos == SAL_N_ELEMENTS(pExcludeProperties) )
297  _rExcludeProperties.push_back(prop);
298  }
299  }
300 
301 
302 } // namespace pcr
303 
304 
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString getPropertyTranslation(sal_Int32 _nId)
Definition: metadata.cxx:164
#define PROPERTY_LABEL
Definition: strings.hxx:90
static OString getPropertyHelpId(sal_Int32 _nId)
Definition: metadata.cxx:171
#define DEF_INFO_1(ident, uinameres, helpid, flag1)
Definition: metadata.cxx:85
#define PROPERTY_AUTOGROW
Definition: strings.hxx:76
PropUIFlags
Definition: metadata.hxx:30
constexpr OUStringLiteral BACKCOLOR
#define PROPERTY_FORMULALIST
Definition: strings.hxx:268
#define PROPERTY_FONT
Definition: strings.hxx:125
sal_Int16 nId
TYPE
#define PROPERTY_POSITIONY
Definition: strings.hxx:75
#define HEIGHT
VISIBLE
#define PROPERTY_WIDTH
Definition: strings.hxx:73
#define PROPERTY_DATASOURCENAME
Definition: strings.hxx:194
#define PROPERTY_BORDERCOLOR
Definition: strings.hxx:101
static sal_Int32 getPropertyId(const OUString &_rName)
Definition: metadata.cxx:157
#define PROPERTY_TYPE
Definition: strings.hxx:217
#define PROPERTY_CONTROLBACKGROUNDTRANSPARENT
Definition: strings.hxx:41
#define PROPERTY_VERTICALALIGN
Definition: strings.hxx:86
const char * sName
static bool isComposable(const OUString &_rPropertyName, const css::uno::Reference< css::inspection::XPropertyHandler > &_xFormComponentHandler)
Definition: metadata.cxx:217
#define SAL_N_ELEMENTS(arr)
OPropertyInfoImpl(const OUString &rName, sal_Int32 _nId, const OUString &aTranslation, const OString &_sHelpId, PropUIFlags _nUIFlags)
Definition: metadata.cxx:56
#define PROPERTY_CONTROLBACKGROUND
Definition: strings.hxx:40
#define PROPERTY_EFFECTIVEDEFAULT
Definition: strings.hxx:91
static sal_uInt16 s_nCount
Definition: metadata.hxx:75
int i
#define PROPERTY_BACKTRANSPARENT
Definition: strings.hxx:39
float u
#define DEF_INFO_2(ident, uinameres, helpid, flag1, flag2)
Definition: metadata.cxx:88
#define PROPERTY_ALIGN
Definition: strings.hxx:216
#define PROPERTY_SCOPE
Definition: strings.hxx:269
#define PROPERTY_EFFECTIVEMAX
Definition: strings.hxx:92
#define PROPERTY_EFFECTIVEMIN
Definition: strings.hxx:93
static const OPropertyInfoImpl * getPropertyInfo()
Definition: metadata.cxx:94
static void getExcludeProperties(::std::vector< css::beans::Property > &_rExcludeProperties, const css::uno::Reference< css::inspection::XPropertyHandler > &_xFormComponentHandler)
Definition: metadata.cxx:230
#define PROPERTY_POSITIONX
Definition: strings.hxx:74
#define PROPERTY_MAXTEXTLEN
Definition: strings.hxx:95
#define PROPERTY_LINECOLOR
Definition: strings.hxx:224
#define PROPERTY_HEIGHT
Definition: strings.hxx:37
const sal_uInt16 WIDTH
static PropUIFlags getPropertyUIFlags(sal_Int32 _nId)
Definition: metadata.cxx:178
static OPropertyInfoImpl * s_pPropertyInfos
Definition: metadata.hxx:76
#define PROPERTY_FILTERPROPOSAL
Definition: strings.hxx:263
#define PROPERTY_EMPTY_IS_NULL
Definition: strings.hxx:262
#define PROPERTY_BORDER
Definition: strings.hxx:100
FORMULA
sal_uInt16 nPos
#define PROPERTY_BACKGROUNDCOLOR
Definition: strings.hxx:200