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