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 :
20 : #include "defaultforminspection.hxx"
21 : #include "pcrcommon.hxx"
22 : #include "pcrservices.hxx"
23 : #include "propresid.hrc"
24 : #include "formresid.hrc"
25 : #include "modulepcr.hxx"
26 : #include "propctrlr.hrc"
27 : #include "formmetadata.hxx"
28 :
29 : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
30 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 : #include <cppuhelper/implbase1.hxx>
32 : #include <osl/diagnose.h>
33 : #include <sal/macros.h>
34 :
35 :
36 4 : extern "C" void SAL_CALL createRegistryInfo_DefaultFormComponentInspectorModel()
37 : {
38 4 : ::pcr::OAutoRegistration< ::pcr::DefaultFormComponentInspectorModel > aAutoRegistration;
39 4 : }
40 :
41 :
42 : namespace pcr
43 : {
44 :
45 :
46 : using ::com::sun::star::uno::Reference;
47 : using ::com::sun::star::uno::Sequence;
48 : using ::com::sun::star::uno::Any;
49 : using ::com::sun::star::uno::RuntimeException;
50 : using ::com::sun::star::uno::XInterface;
51 : using ::com::sun::star::uno::XComponentContext;
52 : using ::com::sun::star::uno::Exception;
53 : using ::com::sun::star::lang::EventObject;
54 : using ::com::sun::star::inspection::PropertyCategoryDescriptor;
55 : using ::com::sun::star::beans::UnknownPropertyException;
56 : using ::com::sun::star::ucb::AlreadyInitializedException;
57 : using ::com::sun::star::lang::IllegalArgumentException;
58 :
59 :
60 : //= DefaultFormComponentInspectorModel
61 :
62 :
63 2 : DefaultFormComponentInspectorModel::DefaultFormComponentInspectorModel( bool _bUseFormFormComponentHandlers )
64 : :ImplInspectorModel()
65 : ,m_bUseFormComponentHandlers( _bUseFormFormComponentHandlers )
66 : ,m_bConstructed( false )
67 2 : ,m_pInfoService( new OPropertyInfoService )
68 : {
69 2 : }
70 :
71 :
72 4 : DefaultFormComponentInspectorModel::~DefaultFormComponentInspectorModel()
73 : {
74 4 : }
75 :
76 :
77 0 : OUString SAL_CALL DefaultFormComponentInspectorModel::getImplementationName( ) throw(RuntimeException, std::exception)
78 : {
79 0 : return getImplementationName_static();
80 : }
81 :
82 :
83 0 : Sequence< OUString > SAL_CALL DefaultFormComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
84 : {
85 0 : return getSupportedServiceNames_static();
86 : }
87 :
88 :
89 4 : OUString DefaultFormComponentInspectorModel::getImplementationName_static( ) throw(RuntimeException)
90 : {
91 4 : return OUString("org.openoffice.comp.extensions.DefaultFormComponentInspectorModel");
92 : }
93 :
94 :
95 4 : Sequence< OUString > DefaultFormComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
96 : {
97 4 : Sequence< OUString > aSupported(1);
98 4 : aSupported[0] = "com.sun.star.form.inspection.DefaultFormComponentInspectorModel";
99 4 : return aSupported;
100 : }
101 :
102 :
103 2 : Reference< XInterface > SAL_CALL DefaultFormComponentInspectorModel::Create( const Reference< XComponentContext >& )
104 : {
105 2 : return *new DefaultFormComponentInspectorModel();
106 : }
107 :
108 :
109 0 : Sequence< Any > SAL_CALL DefaultFormComponentInspectorModel::getHandlerFactories() throw (RuntimeException, std::exception)
110 : {
111 0 : ::osl::MutexGuard aGuard( m_aMutex );
112 :
113 : // service names for all our handlers
114 : struct
115 : {
116 : const sal_Char* serviceName;
117 : bool isFormOnly;
118 : } aFactories[] = {
119 :
120 : // a generic handler for form component properties (must precede the ButtonNavigationHandler)
121 : { "com.sun.star.form.inspection.FormComponentPropertyHandler", false },
122 :
123 : // generic virtual edit properties
124 : { "com.sun.star.form.inspection.EditPropertyHandler", false },
125 :
126 : // a handler which virtualizes the ButtonType property, to provide additional types like
127 : // "move to next record"
128 : { "com.sun.star.form.inspection.ButtonNavigationHandler", false },
129 :
130 : // a handler for script events bound to form components or dialog elements
131 : { "com.sun.star.form.inspection.EventHandler", false },
132 :
133 : // a handler which introduces virtual properties for binding controls to spreadsheet cells
134 : { "com.sun.star.form.inspection.CellBindingPropertyHandler", false },
135 :
136 : // properties related to binding to an XForms DOM node
137 : { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true },
138 :
139 : // properties related to the XSD data against which a control content is validated
140 : { "com.sun.star.form.inspection.XSDValidationPropertyHandler", true },
141 :
142 : // a handler which cares for XForms submissions
143 : { "com.sun.star.form.inspection.SubmissionPropertyHandler", true },
144 :
145 : // a handler which cares for geometry properties of form controls
146 : { "com.sun.star.form.inspection.FormGeometryHandler", true }
147 0 : };
148 :
149 0 : sal_Int32 nFactories = SAL_N_ELEMENTS( aFactories );
150 0 : Sequence< Any > aReturn( nFactories );
151 0 : Any* pReturn = aReturn.getArray();
152 0 : for ( sal_Int32 i = 0; i < nFactories; ++i )
153 : {
154 0 : if ( aFactories[i].isFormOnly && !m_bUseFormComponentHandlers )
155 0 : continue;
156 0 : *pReturn++ <<= OUString::createFromAscii( aFactories[i].serviceName );
157 : }
158 0 : aReturn.realloc( pReturn - aReturn.getArray() );
159 :
160 0 : return aReturn;
161 : }
162 :
163 :
164 0 : Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultFormComponentInspectorModel::describeCategories( ) throw (RuntimeException, std::exception)
165 : {
166 0 : ::osl::MutexGuard aGuard( m_aMutex );
167 :
168 : struct
169 : {
170 : const sal_Char* programmaticName;
171 : sal_uInt16 uiNameResId;
172 : const sal_Char* helpId;
173 : } aCategories[] = {
174 : { "General", RID_STR_PROPPAGE_DEFAULT, HID_FM_PROPDLG_TAB_GENERAL },
175 : { "Data", RID_STR_PROPPAGE_DATA, HID_FM_PROPDLG_TAB_DATA },
176 : { "Events", RID_STR_EVENTS, HID_FM_PROPDLG_TAB_EVT }
177 0 : };
178 :
179 0 : sal_Int32 nCategories = SAL_N_ELEMENTS( aCategories );
180 0 : Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
181 0 : PropertyCategoryDescriptor* pReturn = aReturn.getArray();
182 0 : for ( sal_Int32 i=0; i<nCategories; ++i, ++pReturn )
183 : {
184 0 : pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
185 0 : pReturn->UIName = PcrRes( aCategories[i].uiNameResId ).toString();
186 0 : pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
187 : }
188 :
189 0 : return aReturn;
190 : }
191 :
192 :
193 0 : ::sal_Int32 SAL_CALL DefaultFormComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
194 : {
195 0 : sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
196 0 : if ( nPropertyId == -1 )
197 : {
198 0 : if ( _rPropertyName.indexOf( ';' ) != -1 )
199 : // it's an event. Just give it an arbitrary number - events will be on a separate
200 : // page, and by definition, if two properties have the same OrderIndex, then
201 : // they will be ordered as they appear in the handler's getSupportedProperties.
202 0 : return 1000;
203 0 : return 0;
204 : }
205 0 : return m_pInfoService->getPropertyPos( nPropertyId );
206 : }
207 :
208 :
209 2 : void SAL_CALL DefaultFormComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException, std::exception)
210 : {
211 2 : if ( m_bConstructed )
212 0 : throw AlreadyInitializedException();
213 :
214 2 : StlSyntaxSequence< Any > arguments( _arguments );
215 2 : if ( arguments.empty() )
216 : { // constructor: "createDefault()"
217 2 : createDefault();
218 2 : return;
219 : }
220 :
221 0 : sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
222 0 : if ( arguments.size() == 2 )
223 : { // constructor: "createWithHelpSection( long, long )"
224 0 : if ( !( arguments[0] >>= nMinHelpTextLines ) || !( arguments[1] >>= nMaxHelpTextLines ) )
225 0 : throw IllegalArgumentException( OUString(), *this, 0 );
226 0 : createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
227 0 : return;
228 : }
229 :
230 2 : throw IllegalArgumentException( OUString(), *this, 0 );
231 : }
232 :
233 :
234 2 : void DefaultFormComponentInspectorModel::createDefault()
235 : {
236 2 : m_bConstructed = true;
237 2 : }
238 :
239 :
240 0 : void DefaultFormComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
241 : {
242 0 : if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
243 0 : throw IllegalArgumentException( OUString(), *this, 0 );
244 :
245 0 : enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
246 0 : m_bConstructed = true;
247 0 : }
248 :
249 :
250 12 : } // namespace pcr
251 :
252 :
253 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|