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 "DefaultInspection.hxx"
25 #include <comphelper/sequence.hxx>
26 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #ifndef _REPORT_DLGRESID_HRC
29 #include <RptResId.hrc>
30 #endif
31 #include "ModuleHelper.hxx"
32 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
33 #include "helpids.hrc"
34 #endif
35 #include <cppuhelper/implbase1.hxx>
36 #include <osl/diagnose.h>
37 #include <rtl/ustrbuf.hxx>
38 #include <tools/debug.hxx>
39 #include "metadata.hxx"
40 #include <tools/urlobj.hxx>
41 
42 //........................................................................
43 namespace rptui
44 {
45 //........................................................................
46 	//------------------------------------------------------------------------
47     ::rtl::OUString HelpIdUrl::getHelpURL( const rtl::OString& sHelpId )
48     {
49         ::rtl::OUStringBuffer aBuffer;
50         const ::rtl::OUString aTmp( ::rtl::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ));
51         DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
52         aBuffer.appendAscii( INET_HID_SCHEME );
53         aBuffer.append( aTmp.getStr() );
54         return aBuffer.makeStringAndClear();
55     }
56 
57     /** === begin UNO using === **/
58     using namespace com::sun::star::uno;
59     using namespace com::sun::star;
60     using com::sun::star::inspection::PropertyCategoryDescriptor;
61     /** === end UNO using === **/
62 
63 	//====================================================================
64 	//= DefaultComponentInspectorModel
65 	//====================================================================
66     DBG_NAME(DefaultComponentInspectorModel)
67 	//--------------------------------------------------------------------
68     DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference< XComponentContext >& _rxContext)
69         :m_xContext( _rxContext )
70         ,m_bConstructed( false )
71         ,m_bHasHelpSection( false )
72         ,m_bIsReadOnly(sal_False)
73         ,m_nMinHelpTextLines( 3 )
74         ,m_nMaxHelpTextLines( 8 )
75         ,m_pInfoService(new OPropertyInfoService())
76     {
77         DBG_CTOR(DefaultComponentInspectorModel,NULL);
78     }
79 
80     //------------------------------------------------------------------------
81     DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
82     {
83         DBG_DTOR(DefaultComponentInspectorModel,NULL);
84     }
85 
86 	//------------------------------------------------------------------------
87 	::rtl::OUString SAL_CALL DefaultComponentInspectorModel::getImplementationName(  ) throw(RuntimeException)
88 	{
89 		return getImplementationName_Static();
90 	}
91 
92 	//------------------------------------------------------------------------
93 	sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException)
94 	{
95 		return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
96 	}
97 
98 	//------------------------------------------------------------------------
99 	Sequence< ::rtl::OUString > SAL_CALL DefaultComponentInspectorModel::getSupportedServiceNames(  ) throw(RuntimeException)
100 	{
101 		return getSupportedServiceNames_static();
102 	}
103 
104 	//------------------------------------------------------------------------
105 	::rtl::OUString DefaultComponentInspectorModel::getImplementationName_Static(  ) throw(RuntimeException)
106 	{
107         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel"));
108 	}
109 
110 	//------------------------------------------------------------------------
111 	Sequence< ::rtl::OUString > DefaultComponentInspectorModel::getSupportedServiceNames_static(  ) throw(RuntimeException)
112 	{
113 		Sequence< ::rtl::OUString > aSupported(1);
114         aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel"));
115 		return aSupported;
116 	}
117 
118 	//------------------------------------------------------------------------
119 	Reference< XInterface > SAL_CALL DefaultComponentInspectorModel::create( const Reference< XComponentContext >& _rxContext )
120 	{
121 		return *(new DefaultComponentInspectorModel( _rxContext ));
122 	}
123 
124     //--------------------------------------------------------------------
125     Sequence< Any > SAL_CALL DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException)
126     {
127         ::osl::MutexGuard aGuard( m_aMutex );
128 
129 
130         // service names for all our handlers
131         const struct
132         {
133             const sal_Char* serviceName;
134         } aFactories[] = {
135 
136             { "com.sun.star.report.inspection.ReportComponentHandler"},
137             { "com.sun.star.form.inspection.EditPropertyHandler"},
138             { "com.sun.star.report.inspection.DataProviderHandler"},
139             { "com.sun.star.report.inspection.GeometryHandler"}
140 
141             // generic virtual edit properties
142 
143         };
144 
145         const size_t nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] );
146         Sequence< Any > aReturn( nFactories );
147         Any* pReturn = aReturn.getArray();
148         for ( size_t i = 0; i < nFactories; ++i )
149         {
150             *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName );
151         }
152 
153         return aReturn;
154     }
155     //--------------------------------------------------------------------
156     ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException)
157     {
158         ::osl::MutexGuard aGuard(m_aMutex);
159         return m_bHasHelpSection;
160     }
161 
162     //--------------------------------------------------------------------
163     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException)
164     {
165         ::osl::MutexGuard aGuard(m_aMutex);
166         return m_nMinHelpTextLines;
167     }
168     //--------------------------------------------------------------------
169     ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
170     {
171         ::osl::MutexGuard aGuard(m_aMutex);
172         return m_bIsReadOnly;
173     }
174     //--------------------------------------------------------------------
175     void SAL_CALL DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly ) throw (::com::sun::star::uno::RuntimeException)
176     {
177         ::osl::MutexGuard aGuard(m_aMutex);
178         m_bIsReadOnly = _isreadonly;
179     }
180 
181     //--------------------------------------------------------------------
182     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
183     {
184         ::osl::MutexGuard aGuard(m_aMutex);
185         return m_nMaxHelpTextLines;
186     }
187     //--------------------------------------------------------------------
188     void SAL_CALL DefaultComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
189     {
190         ::osl::MutexGuard aGuard(m_aMutex);
191         if ( m_bConstructed )
192             throw ucb::AlreadyInitializedException();
193 
194         if ( !_arguments.hasElements() )
195         {   // constructor: "createDefault()"
196             createDefault();
197             return;
198         }
199 
200         sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
201         if ( _arguments.getLength() == 2 )
202         {   // constructor: "createWithHelpSection( long, long )"
203             if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) )
204                 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
205             createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
206             return;
207         }
208 
209         throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
210     }
211 
212     //--------------------------------------------------------------------
213     void DefaultComponentInspectorModel::createDefault()
214     {
215         m_bConstructed = true;
216     }
217     //--------------------------------------------------------------------
218     void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
219     {
220         if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
221             throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
222 
223         m_bHasHelpSection = true;
224         m_nMinHelpTextLines = _nMinHelpTextLines;
225         m_nMaxHelpTextLines = _nMaxHelpTextLines;
226         m_bConstructed = true;
227     }
228     //--------------------------------------------------------------------
229     Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultComponentInspectorModel::describeCategories(  ) throw (RuntimeException)
230     {
231         ::osl::MutexGuard aGuard( m_aMutex );
232 
233         const struct
234         {
235             const sal_Char* programmaticName;
236             sal_uInt16          uiNameResId;
237             rtl::OString    helpId;
238         } aCategories[] = {
239             { "General",    RID_STR_PROPPAGE_DEFAULT,   HID_RPT_PROPDLG_TAB_GENERAL },
240             { "Data",       RID_STR_PROPPAGE_DATA,      HID_RPT_PROPDLG_TAB_DATA },
241         };
242 
243         const size_t nCategories = sizeof( aCategories ) / sizeof( aCategories[0] );
244         Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
245         PropertyCategoryDescriptor* pReturn = aReturn.getArray();
246         for ( size_t i=0; i<nCategories; ++i, ++pReturn )
247         {
248             pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName );
249             pReturn->UIName = String( ModuleRes( aCategories[i].uiNameResId ) );
250             pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
251         }
252 
253         return aReturn;
254     }
255 
256     //--------------------------------------------------------------------
257     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
258     {
259         ::osl::MutexGuard aGuard(m_aMutex);
260         const sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
261         if ( nPropertyId != -1 )
262             return nPropertyId;
263 
264         if ( !m_xComponent.is() )
265             try
266             {
267                 m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.DefaultFormComponentInspectorModel")),m_xContext),UNO_QUERY_THROW);
268             }
269             catch(Exception)
270             {
271                 return 0;
272             }
273 
274         return m_xComponent->getPropertyOrderIndex(_rPropertyName);
275     }
276 
277 //........................................................................
278 } // namespace rptui
279 //........................................................................
280 
281