1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 #include "metadata.hxx"
25 #include <svtools/localresaccess.hxx>
26 #include "com/sun/star/inspection/XPropertyHandler.hpp"
27 #include <tools/debug.hxx>
28 #include <comphelper/extract.hxx>
29 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
30 #include "helpids.hrc"
31 #endif
32 #ifndef _RPTUI_DLGRESID_HRC
33 #include "RptResId.hrc"
34 #endif
35 #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC
36 #include "uistrings.hrc"
37 #endif
38 
39 #include <functional>
40 #include <algorithm>
41 
42 //............................................................................
43 namespace rptui
44 {
45 //............................................................................
46 
47 	using namespace ::com::sun::star::uno;
48     using namespace ::com::sun::star;
49 
50 	//========================================================================
51 	//= OPropertyInfoImpl
52 	//========================================================================
53 	struct OPropertyInfoImpl
54 	{
55 		String			sName;
56 		String			sTranslation;
57 		rtl::OString    sHelpId;
58 		sal_Int32       nId;
59 		sal_uInt16      nPos;
60         sal_uInt32      nUIFlags;
61 
62 		OPropertyInfoImpl(
63 						const ::rtl::OUString&		rName,
64 						sal_Int32					_nId,
65 						const String&				aTranslation,
66 						sal_uInt16					nPosId,
67 						const rtl::OString&			_sHelpId,
68                         sal_uInt32                  _nUIFlags);
69 	};
70 
71 	//------------------------------------------------------------------------
72 	OPropertyInfoImpl::OPropertyInfoImpl(const ::rtl::OUString& _rName, sal_Int32 _nId,
73 								   const String& aString, sal_uInt16 nP, const rtl::OString& sHid, sal_uInt32 _nUIFlags)
74 	   :sName(_rName)
75 	   ,sTranslation(aString)
76 	   ,sHelpId(sHid)
77 	   ,nId(_nId)
78 	   ,nPos(nP)
79        ,nUIFlags(_nUIFlags)
80 	{
81 	}
82 
83 	//------------------------------------------------------------------------
84 	// Vergleichen von PropertyInfo
85     struct PropertyInfoLessByName : public ::std::binary_function< OPropertyInfoImpl, OPropertyInfoImpl, bool >
86     {
87         bool operator()( const OPropertyInfoImpl& _lhs, const OPropertyInfoImpl& _rhs )
88         {
89             return _lhs.sName < _rhs.sName;
90         }
91     };
92 
93 	//========================================================================
94 	//= OPropertyInfoService
95 	//========================================================================
96 #define DEF_INFO( ident, uinameres, helpid, flags )   \
97     OPropertyInfoImpl( PROPERTY_##ident, PROPERTY_ID_##ident, \
98             String( ModuleRes( RID_STR_##uinameres ) ), nPos++, HID_RPT_PROP_##helpid, flags )
99 
100 #define DEF_INFO_1( ident, uinameres, helpid, flag1 ) \
101     DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 )
102 
103 #define DEF_INFO_2( ident, uinameres, helpid, flag1, flag2 ) \
104     DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 )
105 
106 #define DEF_INFO_3( ident, uinameres, helpid, flag1, flag2, flag3 ) \
107     DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 )
108 
109 #define DEF_INFO_4( ident, uinameres, helpid, flag1, flag2, flag3, flag4 ) \
110     DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 )
111 
112 #define DEF_INFO_5( ident, uinameres, helpid, flag1, flag2, flag3, flag4, flag5 ) \
113     DEF_INFO( ident, uinameres, helpid, PROP_FLAG_##flag1 | PROP_FLAG_##flag2 | PROP_FLAG_##flag3 | PROP_FLAG_##flag4 | PROP_FLAG_##flag5 )
114 
115     sal_uInt16				OPropertyInfoService::s_nCount = 0;
116 	OPropertyInfoImpl*		OPropertyInfoService::s_pPropertyInfos = NULL;
117 	//------------------------------------------------------------------------
118 	const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo()
119 	{
120 		if ( s_pPropertyInfos )
121             return s_pPropertyInfos;
122 
123 		OModuleClient aResourceAccess;
124 		// this ensures that we have our resource file loaded
125 
126 		sal_uInt16 nPos = 1;
127         static OPropertyInfoImpl aPropertyInfos[] =
128 		{
129         /*
130         DEF_INFO_?( propname and id,   resoure id,         help id,           flags ),
131         */
132              DEF_INFO_1( FORCENEWPAGE,                  FORCENEWPAGE,               FORCENEWPAGE,               COMPOSEABLE )
133             ,DEF_INFO_1( NEWROWORCOL,                   NEWROWORCOL,                NEWROWORCOL,                COMPOSEABLE )
134             ,DEF_INFO_1( KEEPTOGETHER,                  KEEPTOGETHER,               KEEPTOGETHER,               COMPOSEABLE )
135             ,DEF_INFO_1( CANGROW,                       CANGROW,                    CANGROW,                    COMPOSEABLE )
136             ,DEF_INFO_1( CANSHRINK,                     CANSHRINK,                  CANSHRINK,                  COMPOSEABLE )
137             ,DEF_INFO_1( REPEATSECTION,                 REPEATSECTION,              REPEATSECTION,              COMPOSEABLE )
138             ,DEF_INFO_1( PRINTREPEATEDVALUES,           PRINTREPEATEDVALUES,        PRINTREPEATEDVALUES,        COMPOSEABLE )
139             ,DEF_INFO_1( CONDITIONALPRINTEXPRESSION,    CONDITIONALPRINTEXPRESSION, CONDITIONALPRINTEXPRESSION, COMPOSEABLE )
140             ,DEF_INFO_1( STARTNEWCOLUMN,                STARTNEWCOLUMN,             STARTNEWCOLUMN,             COMPOSEABLE )
141             ,DEF_INFO_1( RESETPAGENUMBER,               RESETPAGENUMBER,            RESETPAGENUMBER,            COMPOSEABLE )
142             ,DEF_INFO_1( PRINTWHENGROUPCHANGE,          PRINTWHENGROUPCHANGE,       PRINTWHENGROUPCHANGE,       COMPOSEABLE )
143             ,DEF_INFO_1( VISIBLE,                       VISIBLE,                    VISIBLE,                    COMPOSEABLE )
144             ,DEF_INFO_1( GROUPKEEPTOGETHER,             GROUPKEEPTOGETHER,          GROUPKEEPTOGETHER,          COMPOSEABLE )
145             ,DEF_INFO_1( PAGEHEADEROPTION,              PAGEHEADEROPTION,           PAGEHEADEROPTION,           COMPOSEABLE )
146             ,DEF_INFO_1( PAGEFOOTEROPTION,              PAGEFOOTEROPTION,           PAGEFOOTEROPTION,           COMPOSEABLE )
147             ,DEF_INFO_1( POSITIONX,                     POSITIONX,                  RPT_POSITIONX,              COMPOSEABLE )
148             ,DEF_INFO_1( POSITIONY,                     POSITIONY,                  RPT_POSITIONY,              COMPOSEABLE )
149             ,DEF_INFO_1( WIDTH,                         WIDTH,                      RPT_WIDTH,                  COMPOSEABLE )
150             ,DEF_INFO_1( HEIGHT,                        HEIGHT,                     RPT_HEIGHT,                 COMPOSEABLE )
151             ,DEF_INFO_1( FONT,                          FONT,                       RPT_FONT,                   COMPOSEABLE )
152             ,DEF_INFO_1( PREEVALUATED,                  PREEVALUATED,               PREEVALUATED,               COMPOSEABLE )
153             ,DEF_INFO_1( DEEPTRAVERSING,                DEEPTRAVERSING,             DEEPTRAVERSING,             COMPOSEABLE )
154             ,DEF_INFO_1( FORMULA,                       FORMULA,                    FORMULA,                    COMPOSEABLE )
155             ,DEF_INFO_1( INITIALFORMULA,                INITIALFORMULA,             INITIALFORMULA,             COMPOSEABLE )
156             ,DEF_INFO_2( TYPE,                          TYPE,                       TYPE,                       COMPOSEABLE,DATA_PROPERTY )
157             ,DEF_INFO_2( DATAFIELD,                     DATAFIELD,                  DATAFIELD,                  COMPOSEABLE,DATA_PROPERTY )
158             ,DEF_INFO_2( FORMULALIST,                   FORMULALIST,                FORMULALIST,                COMPOSEABLE,DATA_PROPERTY )
159             ,DEF_INFO_2( SCOPE,                         SCOPE,                      SCOPE,                      COMPOSEABLE,DATA_PROPERTY )
160             ,DEF_INFO_1( PRESERVEIRI,                   PRESERVEIRI,                PRESERVEIRI,                COMPOSEABLE )
161             ,DEF_INFO_1( BACKCOLOR,                     BACKCOLOR,                  BACKCOLOR,                  COMPOSEABLE )
162             ,DEF_INFO_1( CONTROLBACKGROUND,             BACKCOLOR,                  BACKCOLOR,                  COMPOSEABLE )
163             ,DEF_INFO_1( BACKTRANSPARENT,               BACKTRANSPARENT,            BACKTRANSPARENT,            COMPOSEABLE )
164             ,DEF_INFO_1( CONTROLBACKGROUNDTRANSPARENT,  CONTROLBACKGROUNDTRANSPARENT
165                                                                     ,CONTROLBACKGROUNDTRANSPARENT, COMPOSEABLE )
166             ,DEF_INFO_1( CHARTTYPE,                     CHARTTYPE,                  CHARTTYPE,                  COMPOSEABLE )
167             ,DEF_INFO_1( PREVIEW_COUNT,                 PREVIEW_COUNT,              PREVIEW_COUNT,              COMPOSEABLE )
168             ,DEF_INFO_2( MASTERFIELDS,                  MASTERFIELDS,               MASTERFIELDS,               COMPOSEABLE,DATA_PROPERTY )
169             ,DEF_INFO_2( DETAILFIELDS,                  DETAILFIELDS,               DETAILFIELDS,               COMPOSEABLE,DATA_PROPERTY)
170             ,DEF_INFO_1( AREA,                          AREA,                       AREA,                       COMPOSEABLE )
171             ,DEF_INFO_2( MIMETYPE,                      MIMETYPE,                   MIMETYPE,                   COMPOSEABLE,DATA_PROPERTY )
172             ,DEF_INFO_1( PARAADJUST,                    PARAADJUST,                 PARAADJUST,                 COMPOSEABLE )
173             ,DEF_INFO_1( VERTICALALIGN,                 VERTICALALIGN,              VERTICALALIGN,              COMPOSEABLE )
174 		};
175 
176 		s_pPropertyInfos = aPropertyInfos;
177 		s_nCount = sizeof(aPropertyInfos) / sizeof(OPropertyInfoImpl);
178 
179         ::std::sort( aPropertyInfos, aPropertyInfos + s_nCount, PropertyInfoLessByName() );
180 
181         return s_pPropertyInfos;
182 	}
183 
184 	//------------------------------------------------------------------------
185 	sal_Int32 OPropertyInfoService::getPropertyId(const String& _rName) const
186 	{
187 		const OPropertyInfoImpl* pInfo = getPropertyInfo(_rName);
188 		return pInfo ? pInfo->nId : -1;
189 	}
190 
191 	//------------------------------------------------------------------------
192 	String OPropertyInfoService::getPropertyTranslation(sal_Int32 _nId) const
193 	{
194 		const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
195 		return (pInfo) ? pInfo->sTranslation : String();
196 	}
197 
198 	//------------------------------------------------------------------------
199 	rtl::OString OPropertyInfoService::getPropertyHelpId(sal_Int32 _nId) const
200 	{
201 		const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
202 		return (pInfo) ? pInfo->sHelpId : rtl::OString();
203 	}
204 
205 	//------------------------------------------------------------------------
206 	sal_uInt32 OPropertyInfoService::getPropertyUIFlags(sal_Int32 _nId) const
207 	{
208 		const OPropertyInfoImpl* pInfo = getPropertyInfo(_nId);
209 		return (pInfo) ? pInfo->nUIFlags : 0;
210 	}
211 
212 	//------------------------------------------------------------------------
213 	const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(const String& _rName)
214 	{
215 		// intialisierung
216 		if(!s_pPropertyInfos)
217 			getPropertyInfo();
218 		OPropertyInfoImpl  aSearch(_rName, 0L, String(), 0, "", 0);
219 
220 		const OPropertyInfoImpl* pPropInfo = ::std::lower_bound(
221             s_pPropertyInfos, s_pPropertyInfos + s_nCount, aSearch, PropertyInfoLessByName() );
222 
223         if ( ( pPropInfo < s_pPropertyInfos + s_nCount ) && pPropInfo->sName == _rName )
224             return pPropInfo;
225 
226 		return NULL;
227 	}
228 
229 
230 	//------------------------------------------------------------------------
231 	const OPropertyInfoImpl* OPropertyInfoService::getPropertyInfo(sal_Int32 _nId)
232 	{
233 		// intialisierung
234 		if(!s_pPropertyInfos)
235 			getPropertyInfo();
236 
237 		// TODO: a real structure which allows quick access by name as well as by id
238 		for (sal_uInt16 i = 0; i < s_nCount; i++)
239 			if (s_pPropertyInfos[i].nId == _nId)
240 				return &s_pPropertyInfos[i];
241 
242 		return NULL;
243 	}
244 
245     //------------------------------------------------------------------------
246     bool OPropertyInfoService::isComposable( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxFormComponentHandler )
247     {
248         sal_Int32 nId = getPropertyId( _rPropertyName );
249         if ( nId != -1 )
250         {
251             sal_uInt32 nFlags = getPropertyUIFlags( nId );
252             return ( nFlags & PROP_FLAG_COMPOSEABLE ) != 0;
253         }
254 
255         return _rxFormComponentHandler->isComposable( _rPropertyName );
256     }
257 
258     //------------------------------------------------------------------------
259     void OPropertyInfoService::getExcludeProperties(::std::vector< beans::Property >& _rExcludeProperties,const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _xFormComponentHandler)
260     {
261         uno::Sequence< beans::Property > aProps = _xFormComponentHandler->getSupportedProperties();
262         static const ::rtl::OUString pExcludeProperties[] =
263         {
264                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Enabled")),
265                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Printable")),
266                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WordBreak")),
267                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MultiLine")),
268                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag")),
269                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpText")),
270                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HelpURL")),
271                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")),
272                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")),
273                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop")),
274                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex")),
275                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMin")),
276                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ValueMax")),
277                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Spin")),
278                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValue")),
279                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMin")),
280                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinValueMax")),
281                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultSpinValue")),
282                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SpinIncrement")),
283                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Repeat")),
284                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RepeatDelay")),
285                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlLabel")), /// TODO: has to be checked
286                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LabelControl")),
287                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), // comment this out if you want to have title feature for charts
288                 PROPERTY_MAXTEXTLEN,
289                 PROPERTY_EFFECTIVEDEFAULT,
290                 PROPERTY_EFFECTIVEMAX,
291                 PROPERTY_EFFECTIVEMIN,
292                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HideInactiveSelection")),
293                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubmitAction")),
294                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputRequired")),
295                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VerticalAlign")),
296                 PROPERTY_ALIGN,
297                 PROPERTY_EMPTY_IS_NULL,
298                 PROPERTY_FILTERPROPOSAL
299                 ,PROPERTY_POSITIONX
300                 ,PROPERTY_POSITIONY
301                 ,PROPERTY_WIDTH
302                 ,PROPERTY_HEIGHT
303                 ,PROPERTY_FONT
304                 ,PROPERTY_LABEL
305                 ,PROPERTY_LINECOLOR
306                 ,PROPERTY_BORDER
307                 ,PROPERTY_BORDERCOLOR
308                 ,PROPERTY_BACKTRANSPARENT
309                 ,PROPERTY_CONTROLBACKGROUND
310                 ,PROPERTY_BACKGROUNDCOLOR
311                 ,PROPERTY_CONTROLBACKGROUNDTRANSPARENT
312                 ,PROPERTY_FORMULALIST
313                 ,PROPERTY_SCOPE
314                 ,PROPERTY_TYPE
315                 ,PROPERTY_DATASOURCENAME
316                 ,PROPERTY_VERTICALALIGN
317         };
318 
319         beans::Property* pPropsIter = aProps.getArray();
320         beans::Property* pPropsEnd = pPropsIter + aProps.getLength();
321         for (; pPropsIter != pPropsEnd; ++pPropsIter)
322         {
323             size_t nPos = 0;
324             for (; nPos < sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) && pExcludeProperties[nPos] != pPropsIter->Name;++nPos )
325                 ;
326             if ( nPos == sizeof(pExcludeProperties)/sizeof(pExcludeProperties[0]) )
327                 _rExcludeProperties.push_back(*pPropsIter);
328         }
329     }
330 
331 
332 //............................................................................
333 } // namespace pcr
334 //............................................................................
335 
336