1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "precompiled_reportdesign.hxx" 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 #ifndef _REPORT_DLGRESID_HRC 33 #include <RptResId.hrc> 34 #endif 35 #include "ModuleHelper.hxx" 36 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC 37 #include "helpids.hrc" 38 #endif 39 #include <cppuhelper/implbase1.hxx> 40 #include <osl/diagnose.h> 41 #include <rtl/ustrbuf.hxx> 42 #include <tools/debug.hxx> 43 #include "metadata.hxx" 44 #include <tools/urlobj.hxx> 45 46 //........................................................................ 47 namespace rptui 48 { 49 //........................................................................ 50 //------------------------------------------------------------------------ 51 ::rtl::OUString HelpIdUrl::getHelpURL( const rtl::OString& sHelpId ) 52 { 53 ::rtl::OUStringBuffer aBuffer; 54 ::rtl::OUString aTmp( sHelpId, sHelpId.getLength(), RTL_TEXTENCODING_UTF8 ); 55 DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" ); 56 aBuffer.appendAscii( INET_HID_SCHEME ); 57 aBuffer.append( aTmp.getStr() ); 58 return aBuffer.makeStringAndClear(); 59 } 60 61 /** === begin UNO using === **/ 62 using namespace com::sun::star::uno; 63 using namespace com::sun::star; 64 using com::sun::star::inspection::PropertyCategoryDescriptor; 65 /** === end UNO using === **/ 66 67 //==================================================================== 68 //= DefaultComponentInspectorModel 69 //==================================================================== 70 DBG_NAME(DefaultComponentInspectorModel) 71 //-------------------------------------------------------------------- 72 DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference< XComponentContext >& _rxContext) 73 :m_xContext( _rxContext ) 74 ,m_bConstructed( false ) 75 ,m_bHasHelpSection( false ) 76 ,m_bIsReadOnly(sal_False) 77 ,m_nMinHelpTextLines( 3 ) 78 ,m_nMaxHelpTextLines( 8 ) 79 ,m_pInfoService(new OPropertyInfoService()) 80 { 81 DBG_CTOR(DefaultComponentInspectorModel,NULL); 82 } 83 84 //------------------------------------------------------------------------ 85 DefaultComponentInspectorModel::~DefaultComponentInspectorModel() 86 { 87 DBG_DTOR(DefaultComponentInspectorModel,NULL); 88 } 89 90 //------------------------------------------------------------------------ 91 ::rtl::OUString SAL_CALL DefaultComponentInspectorModel::getImplementationName( ) throw(RuntimeException) 92 { 93 return getImplementationName_Static(); 94 } 95 96 //------------------------------------------------------------------------ 97 sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException) 98 { 99 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static()); 100 } 101 102 //------------------------------------------------------------------------ 103 Sequence< ::rtl::OUString > SAL_CALL DefaultComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException) 104 { 105 return getSupportedServiceNames_static(); 106 } 107 108 //------------------------------------------------------------------------ 109 ::rtl::OUString DefaultComponentInspectorModel::getImplementationName_Static( ) throw(RuntimeException) 110 { 111 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel")); 112 } 113 114 //------------------------------------------------------------------------ 115 Sequence< ::rtl::OUString > DefaultComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException) 116 { 117 Sequence< ::rtl::OUString > aSupported(1); 118 aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel")); 119 return aSupported; 120 } 121 122 //------------------------------------------------------------------------ 123 Reference< XInterface > SAL_CALL DefaultComponentInspectorModel::create( const Reference< XComponentContext >& _rxContext ) 124 { 125 return *(new DefaultComponentInspectorModel( _rxContext )); 126 } 127 128 //-------------------------------------------------------------------- 129 Sequence< Any > SAL_CALL DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException) 130 { 131 ::osl::MutexGuard aGuard( m_aMutex ); 132 133 134 // service names for all our handlers 135 const struct 136 { 137 const sal_Char* serviceName; 138 } aFactories[] = { 139 140 { "com.sun.star.report.inspection.ReportComponentHandler"}, 141 { "com.sun.star.form.inspection.EditPropertyHandler"}, 142 { "com.sun.star.report.inspection.DataProviderHandler"}, 143 { "com.sun.star.report.inspection.GeometryHandler"} 144 145 // generic virtual edit properties 146 147 }; 148 149 const size_t nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] ); 150 Sequence< Any > aReturn( nFactories ); 151 Any* pReturn = aReturn.getArray(); 152 for ( size_t i = 0; i < nFactories; ++i ) 153 { 154 *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName ); 155 } 156 157 return aReturn; 158 } 159 //-------------------------------------------------------------------- 160 ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException) 161 { 162 ::osl::MutexGuard aGuard(m_aMutex); 163 return m_bHasHelpSection; 164 } 165 166 //-------------------------------------------------------------------- 167 ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException) 168 { 169 ::osl::MutexGuard aGuard(m_aMutex); 170 return m_nMinHelpTextLines; 171 } 172 //-------------------------------------------------------------------- 173 ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException) 174 { 175 ::osl::MutexGuard aGuard(m_aMutex); 176 return m_bIsReadOnly; 177 } 178 //-------------------------------------------------------------------- 179 void SAL_CALL DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly ) throw (::com::sun::star::uno::RuntimeException) 180 { 181 ::osl::MutexGuard aGuard(m_aMutex); 182 m_bIsReadOnly = _isreadonly; 183 } 184 185 //-------------------------------------------------------------------- 186 ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException) 187 { 188 ::osl::MutexGuard aGuard(m_aMutex); 189 return m_nMaxHelpTextLines; 190 } 191 //-------------------------------------------------------------------- 192 void SAL_CALL DefaultComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 193 { 194 ::osl::MutexGuard aGuard(m_aMutex); 195 if ( m_bConstructed ) 196 throw ucb::AlreadyInitializedException(); 197 198 if ( !_arguments.hasElements() ) 199 { // constructor: "createDefault()" 200 createDefault(); 201 return; 202 } 203 204 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 ); 205 if ( _arguments.getLength() == 2 ) 206 { // constructor: "createWithHelpSection( long, long )" 207 if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) ) 208 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 209 createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines ); 210 return; 211 } 212 213 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 214 } 215 216 //-------------------------------------------------------------------- 217 void DefaultComponentInspectorModel::createDefault() 218 { 219 m_bConstructed = true; 220 } 221 //-------------------------------------------------------------------- 222 void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines ) 223 { 224 if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) ) 225 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 226 227 m_bHasHelpSection = true; 228 m_nMinHelpTextLines = _nMinHelpTextLines; 229 m_nMaxHelpTextLines = _nMaxHelpTextLines; 230 m_bConstructed = true; 231 } 232 //-------------------------------------------------------------------- 233 Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultComponentInspectorModel::describeCategories( ) throw (RuntimeException) 234 { 235 ::osl::MutexGuard aGuard( m_aMutex ); 236 237 const struct 238 { 239 const sal_Char* programmaticName; 240 sal_uInt16 uiNameResId; 241 rtl::OString helpId; 242 } aCategories[] = { 243 { "General", RID_STR_PROPPAGE_DEFAULT, HID_RPT_PROPDLG_TAB_GENERAL }, 244 { "Data", RID_STR_PROPPAGE_DATA, HID_RPT_PROPDLG_TAB_DATA }, 245 }; 246 247 const size_t nCategories = sizeof( aCategories ) / sizeof( aCategories[0] ); 248 Sequence< PropertyCategoryDescriptor > aReturn( nCategories ); 249 PropertyCategoryDescriptor* pReturn = aReturn.getArray(); 250 for ( size_t i=0; i<nCategories; ++i, ++pReturn ) 251 { 252 pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName ); 253 pReturn->UIName = String( ModuleRes( aCategories[i].uiNameResId ) ); 254 pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId ); 255 } 256 257 return aReturn; 258 } 259 260 //-------------------------------------------------------------------- 261 ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException) 262 { 263 ::osl::MutexGuard aGuard(m_aMutex); 264 const sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) ); 265 if ( nPropertyId != -1 ) 266 return nPropertyId; 267 268 if ( !m_xComponent.is() ) 269 try 270 { 271 m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.DefaultFormComponentInspectorModel")),m_xContext),UNO_QUERY_THROW); 272 } 273 catch(Exception) 274 { 275 return 0; 276 } 277 278 return m_xComponent->getPropertyOrderIndex(_rPropertyName); 279 } 280 281 //........................................................................ 282 } // namespace rptui 283 //........................................................................ 284 285