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