Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "DefaultInspection.hxx"
29 : : #include <comphelper/sequence.hxx>
30 : : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
31 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 : : #include <RptResId.hrc>
33 : : #include "ModuleHelper.hxx"
34 : : #include "helpids.hrc"
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 : 0 : ::rtl::OUString HelpIdUrl::getHelpURL( const rtl::OString& sHelpId )
48 : : {
49 : 0 : ::rtl::OUStringBuffer aBuffer;
50 : 0 : ::rtl::OUString aTmp( rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8) );
51 : : DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
52 : 0 : aBuffer.appendAscii( INET_HID_SCHEME );
53 : 0 : aBuffer.append( aTmp.getStr() );
54 : 0 : 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 : 0 : 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 : 0 : ,m_pInfoService(new OPropertyInfoService())
76 : : {
77 : : DBG_CTOR(DefaultComponentInspectorModel,NULL);
78 : 0 : }
79 : :
80 : : //------------------------------------------------------------------------
81 : 0 : DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
82 : : {
83 : : DBG_DTOR(DefaultComponentInspectorModel,NULL);
84 : 0 : }
85 : :
86 : : //------------------------------------------------------------------------
87 : 0 : ::rtl::OUString SAL_CALL DefaultComponentInspectorModel::getImplementationName( ) throw(RuntimeException)
88 : : {
89 : 0 : return getImplementationName_Static();
90 : : }
91 : :
92 : : //------------------------------------------------------------------------
93 : 0 : sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException)
94 : : {
95 : 0 : return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
96 : : }
97 : :
98 : : //------------------------------------------------------------------------
99 : 0 : Sequence< ::rtl::OUString > SAL_CALL DefaultComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException)
100 : : {
101 : 0 : return getSupportedServiceNames_static();
102 : : }
103 : :
104 : : //------------------------------------------------------------------------
105 : 0 : ::rtl::OUString DefaultComponentInspectorModel::getImplementationName_Static( ) throw(RuntimeException)
106 : : {
107 : 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel"));
108 : : }
109 : :
110 : : //------------------------------------------------------------------------
111 : 0 : Sequence< ::rtl::OUString > DefaultComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
112 : : {
113 : 0 : Sequence< ::rtl::OUString > aSupported(1);
114 : 0 : aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel"));
115 : 0 : return aSupported;
116 : : }
117 : :
118 : : //------------------------------------------------------------------------
119 : 0 : Reference< XInterface > SAL_CALL DefaultComponentInspectorModel::create( const Reference< XComponentContext >& _rxContext )
120 : : {
121 : 0 : return *(new DefaultComponentInspectorModel( _rxContext ));
122 : : }
123 : :
124 : : //--------------------------------------------------------------------
125 : 0 : Sequence< Any > SAL_CALL DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException)
126 : : {
127 : 0 : ::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 : 0 : };
144 : :
145 : 0 : const size_t nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] );
146 : 0 : Sequence< Any > aReturn( nFactories );
147 : 0 : Any* pReturn = aReturn.getArray();
148 : 0 : for ( size_t i = 0; i < nFactories; ++i )
149 : : {
150 : 0 : *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName );
151 : : }
152 : :
153 : 0 : return aReturn;
154 : : }
155 : : //--------------------------------------------------------------------
156 : 0 : ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException)
157 : : {
158 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
159 : 0 : return m_bHasHelpSection;
160 : : }
161 : :
162 : : //--------------------------------------------------------------------
163 : 0 : ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException)
164 : : {
165 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
166 : 0 : return m_nMinHelpTextLines;
167 : : }
168 : : //--------------------------------------------------------------------
169 : 0 : ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
170 : : {
171 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
172 : 0 : return m_bIsReadOnly;
173 : : }
174 : : //--------------------------------------------------------------------
175 : 0 : void SAL_CALL DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly ) throw (::com::sun::star::uno::RuntimeException)
176 : : {
177 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
178 : 0 : m_bIsReadOnly = _isreadonly;
179 : 0 : }
180 : :
181 : : //--------------------------------------------------------------------
182 : 0 : ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
183 : : {
184 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
185 : 0 : return m_nMaxHelpTextLines;
186 : : }
187 : : //--------------------------------------------------------------------
188 : 0 : void SAL_CALL DefaultComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
189 : : {
190 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
191 : 0 : if ( m_bConstructed )
192 : 0 : throw ucb::AlreadyInitializedException();
193 : :
194 : 0 : if ( !_arguments.hasElements() )
195 : : { // constructor: "createDefault()"
196 : 0 : createDefault();
197 : : return;
198 : : }
199 : :
200 : 0 : sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
201 : 0 : if ( _arguments.getLength() == 2 )
202 : : { // constructor: "createWithHelpSection( long, long )"
203 : 0 : if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) )
204 : 0 : throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
205 : 0 : createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
206 : : return;
207 : : }
208 : :
209 : 0 : throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
210 : : }
211 : :
212 : : //--------------------------------------------------------------------
213 : 0 : void DefaultComponentInspectorModel::createDefault()
214 : : {
215 : 0 : m_bConstructed = true;
216 : 0 : }
217 : : //--------------------------------------------------------------------
218 : 0 : void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
219 : : {
220 : 0 : if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
221 : 0 : throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
222 : :
223 : 0 : m_bHasHelpSection = true;
224 : 0 : m_nMinHelpTextLines = _nMinHelpTextLines;
225 : 0 : m_nMaxHelpTextLines = _nMaxHelpTextLines;
226 : 0 : m_bConstructed = true;
227 : 0 : }
228 : : //--------------------------------------------------------------------
229 : 0 : Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultComponentInspectorModel::describeCategories( ) throw (RuntimeException)
230 : : {
231 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
232 : :
233 : : const struct
234 : 0 : {
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 : 0 : };
242 : :
243 : 0 : const size_t nCategories = sizeof( aCategories ) / sizeof( aCategories[0] );
244 : 0 : Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
245 : 0 : PropertyCategoryDescriptor* pReturn = aReturn.getArray();
246 : 0 : for ( size_t i=0; i<nCategories; ++i, ++pReturn )
247 : : {
248 : 0 : pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName );
249 : 0 : pReturn->UIName = String( ModuleRes( aCategories[i].uiNameResId ) );
250 : 0 : pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
251 : : }
252 : :
253 : 0 : return aReturn;
254 : : }
255 : :
256 : : //--------------------------------------------------------------------
257 : 0 : ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
258 : : {
259 : 0 : ::osl::MutexGuard aGuard(m_aMutex);
260 : 0 : const sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
261 : 0 : if ( nPropertyId != -1 )
262 : 0 : return nPropertyId;
263 : :
264 : 0 : if ( !m_xComponent.is() )
265 : : try
266 : : {
267 : 0 : 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 : 0 : catch(const Exception &)
270 : : {
271 : 0 : return 0;
272 : : }
273 : :
274 : 0 : return m_xComponent->getPropertyOrderIndex(_rPropertyName);
275 : : }
276 : :
277 : : //........................................................................
278 : : } // namespace rptui
279 : : //........................................................................
280 : :
281 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|