LibreOffice Module extensions (master) 1
defaultforminspection.cxx
Go to the documentation of this file.
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
21#include "pcrcommon.hxx"
22#include <helpids.h>
23#include <strings.hrc>
24#include "modulepcr.hxx"
25#include "formmetadata.hxx"
26
27#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
28#include <com/sun/star/lang/IllegalArgumentException.hpp>
29#include <com/sun/star/uno/XComponentContext.hpp>
30#include <sal/macros.h>
31
32
33namespace pcr
34{
35
36
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::uno::Any;
39 using ::com::sun::star::uno::XInterface;
40 using ::com::sun::star::uno::XComponentContext;
41 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
42 using ::com::sun::star::ucb::AlreadyInitializedException;
43 using ::com::sun::star::lang::IllegalArgumentException;
44
46 :m_bUseFormComponentHandlers( _bUseFormFormComponentHandlers )
47 ,m_bConstructed( false )
48 ,m_pInfoService( new OPropertyInfoService )
49 {
50 }
51
52
54 {
55 }
56
57
59 {
60 return "org.openoffice.comp.extensions.DefaultFormComponentInspectorModel";
61 }
62
63
65 {
66 return { "com.sun.star.form.inspection.DefaultFormComponentInspectorModel" };
67 }
68
69
71 {
72 ::osl::MutexGuard aGuard( m_aMutex );
73
74 // service names for all our handlers
75 static struct
76 {
77 const char* serviceName;
78 bool isFormOnly;
79 } const aFactories[] = {
80
81 // a generic handler for form component properties (must precede the ButtonNavigationHandler)
82 { "com.sun.star.form.inspection.FormComponentPropertyHandler", false },
83
84 // generic virtual edit properties
85 { "com.sun.star.form.inspection.EditPropertyHandler", false },
86
87 // a handler which virtualizes the ButtonType property, to provide additional types like
88 // "move to next record"
89 { "com.sun.star.form.inspection.ButtonNavigationHandler", false },
90
91 // a handler for script events bound to form components or dialog elements
92 { "com.sun.star.form.inspection.EventHandler", false },
93
94 // a handler which introduces virtual properties for binding controls to spreadsheet cells
95 { "com.sun.star.form.inspection.CellBindingPropertyHandler", false },
96
97 // properties related to binding to an XForms DOM node
98 { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true },
99
100 // properties related to the XSD data against which a control content is validated
101 { "com.sun.star.form.inspection.XSDValidationPropertyHandler", true },
102
103 // a handler which cares for XForms submissions
104 { "com.sun.star.form.inspection.SubmissionPropertyHandler", true },
105
106 // a handler which cares for geometry properties of form controls
107 { "com.sun.star.form.inspection.FormGeometryHandler", true }
108 };
109
110 sal_Int32 nFactories = SAL_N_ELEMENTS( aFactories );
111 Sequence< Any > aReturn( nFactories );
112 Any* pReturn = aReturn.getArray();
113 for ( sal_Int32 i = 0; i < nFactories; ++i )
114 {
115 if ( aFactories[i].isFormOnly && !m_bUseFormComponentHandlers )
116 continue;
117 *pReturn++ <<= OUString::createFromAscii( aFactories[i].serviceName );
118 }
119 aReturn.realloc( pReturn - aReturn.getArray() );
120
121 return aReturn;
122 }
123
124
125 Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultFormComponentInspectorModel::describeCategories( )
126 {
127 ::osl::MutexGuard aGuard( m_aMutex );
128
129 static struct
130 {
131 const char* programmaticName;
132 TranslateId uiNameResId;
133 rtl::OUStringConstExpr helpId;
134 } const aCategories[] = {
135 { "General", RID_STR_PROPPAGE_DEFAULT, HID_FM_PROPDLG_TAB_GENERAL },
136 { "Data", RID_STR_PROPPAGE_DATA, HID_FM_PROPDLG_TAB_DATA },
137 { "Events", RID_STR_EVENTS, HID_FM_PROPDLG_TAB_EVT }
138 };
139
140 sal_Int32 nCategories = SAL_N_ELEMENTS( aCategories );
141 Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
142 PropertyCategoryDescriptor* pReturn = aReturn.getArray();
143 for ( sal_Int32 i=0; i<nCategories; ++i, ++pReturn )
144 {
145 pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
146 pReturn->UIName = PcrRes( aCategories[i].uiNameResId );
147 pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId.asView() );
148 }
149
150 return aReturn;
151 }
152
153
154 ::sal_Int32 SAL_CALL DefaultFormComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName )
155 {
156 sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
157 if ( nPropertyId == -1 )
158 {
159 if ( _rPropertyName.indexOf( ';' ) != -1 )
160 // it's an event. Just give it an arbitrary number - events will be on a separate
161 // page, and by definition, if two properties have the same OrderIndex, then
162 // they will be ordered as they appear in the handler's getSupportedProperties.
163 return 1000;
164 return 0;
165 }
166 return m_pInfoService->getPropertyPos( nPropertyId );
167 }
168
169
170 void SAL_CALL DefaultFormComponentInspectorModel::initialize( const Sequence< Any >& _arguments )
171 {
172 if ( m_bConstructed )
173 throw AlreadyInitializedException();
174
175 StlSyntaxSequence< Any > arguments( _arguments );
176 if ( arguments.empty() )
177 { // constructor: "createDefault()"
178 m_bConstructed = true;
179 return;
180 }
181
182 if ( arguments.size() == 2 )
183 { // constructor: "createWithHelpSection( long, long )"
184 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
185 if ( !( arguments[0] >>= nMinHelpTextLines ) || !( arguments[1] >>= nMaxHelpTextLines ) )
186 throw IllegalArgumentException( OUString(), *this, 0 );
187 createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
188 return;
189 }
190
191 throw IllegalArgumentException( OUString(), *this, 0 );
192 }
193
194
195 void DefaultFormComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
196 {
197 if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
198 throw IllegalArgumentException( OUString(), *this, 0 );
199
200 enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
201 m_bConstructed = true;
202 }
203
204
205} // namespace pcr
206
207extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
209 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
210{
211 return cppu::acquire(new pcr::DefaultFormComponentInspectorModel(context));
212}
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropFlags nPropertyId
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
DefaultFormComponentInspectorModel(bool _bUseFormFormComponentHandlers=true)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex(const OUString &PropertyName) override
void createWithHelpSection(sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines)
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getHandlerFactories() override
virtual css::uno::Sequence< css::inspection::PropertyCategoryDescriptor > SAL_CALL describeCategories() override
std::unique_ptr< OPropertyInfoService > m_pInfoService
access to property meta data
virtual OUString SAL_CALL getImplementationName() override
static OUString getHelpURL(std::u16string_view)
Definition: pcrcommon.cxx:47
void enableHelpSectionProperties(sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines)
bool empty() const
Definition: pcrcommon.hxx:94
sal_Int32 size() const
Definition: pcrcommon.hxx:93
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_DefaultFormComponentInspectorModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral HID_FM_PROPDLG_TAB_EVT
Definition: helpids.h:299
constexpr OUStringLiteral HID_FM_PROPDLG_TAB_GENERAL
Definition: helpids.h:297
constexpr OUStringLiteral HID_FM_PROPDLG_TAB_DATA
Definition: helpids.h:298
#define SAL_N_ELEMENTS(arr)
int i
a property handler for any virtual string properties
Definition: browserline.cxx:39
OUString PcrRes(TranslateId aId)
Definition: modulepcr.cxx:26