bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / propctrlr / defaultforminspection.cxx
blob7fb4906752b4ed94cbe2e24d7187773ba6287473
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "defaultforminspection.hxx"
21 #include "pcrcommon.hxx"
22 #include "propresid.hrc"
23 #include "formresid.hrc"
24 #include "modulepcr.hxx"
25 #include "propctrlr.hrc"
26 #include "formmetadata.hxx"
28 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <cppuhelper/implbase1.hxx>
31 #include <osl/diagnose.h>
32 #include <sal/macros.h>
34 //------------------------------------------------------------------------
35 extern "C" void SAL_CALL createRegistryInfo_DefaultFormComponentInspectorModel()
37 ::pcr::OAutoRegistration< ::pcr::DefaultFormComponentInspectorModel > aAutoRegistration;
40 //........................................................................
41 namespace pcr
43 //........................................................................
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::RuntimeException;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::uno::XComponentContext;
51 using ::com::sun::star::uno::Exception;
52 using ::com::sun::star::lang::EventObject;
53 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
54 using ::com::sun::star::beans::UnknownPropertyException;
55 using ::com::sun::star::ucb::AlreadyInitializedException;
56 using ::com::sun::star::lang::IllegalArgumentException;
58 //====================================================================
59 //= DefaultFormComponentInspectorModel
60 //====================================================================
61 //--------------------------------------------------------------------
62 DefaultFormComponentInspectorModel::DefaultFormComponentInspectorModel( const Reference< XComponentContext >& _rxContext, bool _bUseFormFormComponentHandlers )
63 :ImplInspectorModel( _rxContext )
64 ,m_bUseFormComponentHandlers( _bUseFormFormComponentHandlers )
65 ,m_bConstructed( false )
66 ,m_pInfoService( new OPropertyInfoService )
70 //------------------------------------------------------------------------
71 DefaultFormComponentInspectorModel::~DefaultFormComponentInspectorModel()
75 //------------------------------------------------------------------------
76 OUString SAL_CALL DefaultFormComponentInspectorModel::getImplementationName( ) throw(RuntimeException)
78 return getImplementationName_static();
81 //------------------------------------------------------------------------
82 Sequence< OUString > SAL_CALL DefaultFormComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException)
84 return getSupportedServiceNames_static();
87 //------------------------------------------------------------------------
88 OUString DefaultFormComponentInspectorModel::getImplementationName_static( ) throw(RuntimeException)
90 return OUString("org.openoffice.comp.extensions.DefaultFormComponentInspectorModel");
93 //------------------------------------------------------------------------
94 Sequence< OUString > DefaultFormComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
96 Sequence< OUString > aSupported(1);
97 aSupported[0] = OUString("com.sun.star.form.inspection.DefaultFormComponentInspectorModel");
98 return aSupported;
101 //------------------------------------------------------------------------
102 Reference< XInterface > SAL_CALL DefaultFormComponentInspectorModel::Create( const Reference< XComponentContext >& _rxContext )
104 return *new DefaultFormComponentInspectorModel( _rxContext );
107 //--------------------------------------------------------------------
108 Sequence< Any > SAL_CALL DefaultFormComponentInspectorModel::getHandlerFactories() throw (RuntimeException)
110 ::osl::MutexGuard aGuard( m_aMutex );
112 // service names for all our handlers
113 struct
115 const sal_Char* serviceName;
116 bool isFormOnly;
117 } aFactories[] = {
119 // a generic handler for form component properties (must precede the ButtonNavigationHandler)
120 { "com.sun.star.form.inspection.FormComponentPropertyHandler", false },
122 // generic virtual edit properties
123 { "com.sun.star.form.inspection.EditPropertyHandler", false },
125 // a handler which virtualizes the ButtonType property, to provide additional types like
126 // "move to next record"
127 { "com.sun.star.form.inspection.ButtonNavigationHandler", false },
129 // a handler for script events bound to form components or dialog elements
130 { "com.sun.star.form.inspection.EventHandler", false },
132 // a handler which introduces virtual properties for binding controls to spreadsheet cells
133 { "com.sun.star.form.inspection.CellBindingPropertyHandler", false },
135 // properties related to binding to an XForms DOM node
136 { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true },
138 // properties related to the XSD data against which a control content is validated
139 { "com.sun.star.form.inspection.XSDValidationPropertyHandler", true },
141 // a handler which cares for XForms submissions
142 { "com.sun.star.form.inspection.SubmissionPropertyHandler", true },
144 // a handler which cares for geometry properties of form controls
145 { "com.sun.star.form.inspection.FormGeometryHandler", true }
148 sal_Int32 nFactories = SAL_N_ELEMENTS( aFactories );
149 Sequence< Any > aReturn( nFactories );
150 Any* pReturn = aReturn.getArray();
151 for ( sal_Int32 i = 0; i < nFactories; ++i )
153 if ( aFactories[i].isFormOnly && !m_bUseFormComponentHandlers )
154 continue;
155 *pReturn++ <<= OUString::createFromAscii( aFactories[i].serviceName );
157 aReturn.realloc( pReturn - aReturn.getArray() );
159 return aReturn;
162 //--------------------------------------------------------------------
163 Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultFormComponentInspectorModel::describeCategories( ) throw (RuntimeException)
165 ::osl::MutexGuard aGuard( m_aMutex );
167 struct
169 const sal_Char* programmaticName;
170 sal_uInt16 uiNameResId;
171 const sal_Char* helpId;
172 } aCategories[] = {
173 { "General", RID_STR_PROPPAGE_DEFAULT, HID_FM_PROPDLG_TAB_GENERAL },
174 { "Data", RID_STR_PROPPAGE_DATA, HID_FM_PROPDLG_TAB_DATA },
175 { "Events", RID_STR_EVENTS, HID_FM_PROPDLG_TAB_EVT }
178 sal_Int32 nCategories = SAL_N_ELEMENTS( aCategories );
179 Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
180 PropertyCategoryDescriptor* pReturn = aReturn.getArray();
181 for ( sal_Int32 i=0; i<nCategories; ++i, ++pReturn )
183 pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
184 pReturn->UIName = String( PcrRes( aCategories[i].uiNameResId ) );
185 pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
188 return aReturn;
191 //--------------------------------------------------------------------
192 ::sal_Int32 SAL_CALL DefaultFormComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName ) throw (RuntimeException)
194 sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
195 if ( nPropertyId == -1 )
197 if ( _rPropertyName.indexOf( ';' ) != -1 )
198 // it's an event. Just give it an arbitrary number - events will be on a separate
199 // page, and by definition, if two properties have the same OrderIndex, then
200 // they will be ordered as they appear in the handler's getSupportedProperties.
201 return 1000;
202 return 0;
204 return m_pInfoService->getPropertyPos( nPropertyId );
207 //--------------------------------------------------------------------
208 void SAL_CALL DefaultFormComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
210 if ( m_bConstructed )
211 throw AlreadyInitializedException();
213 StlSyntaxSequence< Any > arguments( _arguments );
214 if ( arguments.empty() )
215 { // constructor: "createDefault()"
216 createDefault();
217 return;
220 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
221 if ( arguments.size() == 2 )
222 { // constructor: "createWithHelpSection( long, long )"
223 if ( !( arguments[0] >>= nMinHelpTextLines ) || !( arguments[1] >>= nMaxHelpTextLines ) )
224 throw IllegalArgumentException( OUString(), *this, 0 );
225 createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
226 return;
229 throw IllegalArgumentException( OUString(), *this, 0 );
232 //--------------------------------------------------------------------
233 void DefaultFormComponentInspectorModel::createDefault()
235 m_bConstructed = true;
238 //--------------------------------------------------------------------
239 void DefaultFormComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
241 if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
242 throw IllegalArgumentException( OUString(), *this, 0 );
244 enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
245 m_bConstructed = true;
248 //........................................................................
249 } // namespace pcr
250 //........................................................................
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */