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