LibreOffice Module extensions (master) 1
objectinspectormodel.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
20#include "pcrcommon.hxx"
22
23#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
24#include <com/sun/star/lang/IllegalArgumentException.hpp>
25#include <com/sun/star/uno/XComponentContext.hpp>
26
27
28namespace pcr
29{
30
31
32 using ::com::sun::star::uno::XComponentContext;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::Any;
35 using ::com::sun::star::inspection::PropertyCategoryDescriptor;
36 using ::com::sun::star::uno::XInterface;
37 using ::com::sun::star::lang::IllegalArgumentException;
38 using ::com::sun::star::ucb::AlreadyInitializedException;
39
40
41 //= ObjectInspectorModel
42
43 namespace {
44
45 class ObjectInspectorModel : public ImplInspectorModel
46 {
47 private:
48 Sequence< Any > m_aFactories;
49
50 public:
51 ObjectInspectorModel();
52
53 // XObjectInspectorModel
54 virtual Sequence< Any > SAL_CALL getHandlerFactories() override;
55 virtual Sequence< PropertyCategoryDescriptor > SAL_CALL describeCategories( ) override;
56 virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex( const OUString& PropertyName ) override;
57
58 // XInitialization
59 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
60
61 // XServiceInfo
62 virtual OUString SAL_CALL getImplementationName( ) override;
63 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
64
65 protected:
66 void createDefault();
67 void createWithHandlerFactories( const Sequence< Any >& _rFactories );
68 void createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines );
69
70 private:
73 void impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition );
74 };
75
76 }
77
78 //= ObjectInspectorModel
79
80 ObjectInspectorModel::ObjectInspectorModel()
81 {
82 }
83
84
85 Sequence< Any > SAL_CALL ObjectInspectorModel::getHandlerFactories()
86 {
87 return m_aFactories;
88 }
89
90
91 Sequence< PropertyCategoryDescriptor > SAL_CALL ObjectInspectorModel::describeCategories( )
92 {
93 // no category info provided by this default implementation
94 return Sequence< PropertyCategoryDescriptor >( );
95 }
96
97
98 ::sal_Int32 SAL_CALL ObjectInspectorModel::getPropertyOrderIndex( const OUString& /*PropertyName*/ )
99 {
100 // no ordering provided by this default implementation
101 return 0;
102 }
103
104
105 void SAL_CALL ObjectInspectorModel::initialize( const Sequence< Any >& _arguments )
106 {
107 ::osl::MutexGuard aGuard( m_aMutex );
108 if ( m_aFactories.hasElements() )
109 throw AlreadyInitializedException();
110
111 StlSyntaxSequence< Any > arguments( _arguments );
112 if ( arguments.empty() )
113 { // constructor: "createDefault()"
115 return;
116 }
117
118 Sequence< Any > factories;
119 impl_verifyArgument_throw( arguments[0] >>= factories, 1 );
120
121 if ( arguments.size() == 1 )
122 { // constructor: "createWithHandlerFactories( any[] )"
123 createWithHandlerFactories( factories );
124 return;
125 }
126
127 if ( arguments.size() == 3 )
128 { // constructor: "createWithHandlerFactoriesAndHelpSection( any[], long, long )"
129 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
130 impl_verifyArgument_throw( arguments[1] >>= nMinHelpTextLines, 2 );
131 impl_verifyArgument_throw( arguments[2] >>= nMaxHelpTextLines, 3 );
132 createWithHandlerFactoriesAndHelpSection( factories, nMinHelpTextLines, nMaxHelpTextLines );
133 return;
134 }
135
136 impl_verifyArgument_throw( false, 2 );
137 }
138
139
140 OUString SAL_CALL ObjectInspectorModel::getImplementationName( )
141 {
142 return "org.openoffice.comp.extensions.ObjectInspectorModel";
143 }
144
145
146 Sequence< OUString > SAL_CALL ObjectInspectorModel::getSupportedServiceNames( )
147 {
148 return { "com.sun.star.inspection.ObjectInspectorModel" };
149 }
150
151
152 void ObjectInspectorModel::createDefault()
153 {
154 m_aFactories = { Any(OUString( "com.sun.star.inspection.GenericPropertyHandler" )) };
155 }
156
157
158 void ObjectInspectorModel::createWithHandlerFactories( const Sequence< Any >& _rFactories )
159 {
160 impl_verifyArgument_throw( _rFactories.hasElements(), 1 );
161 m_aFactories = _rFactories;
162 }
163
164
165 void ObjectInspectorModel::createWithHandlerFactoriesAndHelpSection( const Sequence< Any >& _rFactories, sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
166 {
167 impl_verifyArgument_throw( _rFactories.hasElements(), 1 );
168 impl_verifyArgument_throw( _nMinHelpTextLines >= 1, 2 );
169 impl_verifyArgument_throw( _nMaxHelpTextLines >= 1, 3 );
170 impl_verifyArgument_throw( _nMinHelpTextLines <= _nMaxHelpTextLines, 2 );
171
172 m_aFactories = _rFactories;
173 enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
174 }
175
176
177 void ObjectInspectorModel::impl_verifyArgument_throw( bool _bCondition, sal_Int16 _nArgumentPosition )
178 {
179 if ( !_bCondition )
180 throw IllegalArgumentException( OUString(), *this, _nArgumentPosition );
181 }
182
183
184} // namespace pcr
185
186extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
188 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
189{
190 return cppu::acquire(new pcr::ObjectInspectorModel());
191}
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
Definition: logger.cxx:98
css::uno::Reference< css::uno::XInterface > createDefault(css::uno::Reference< css::uno::XComponentContext > const &context)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
a property handler for any virtual string properties
Definition: browserline.cxx:39
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_ObjectInspectorModel_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)