cid#1640468 Dereference after null check
[LibreOffice.git] / extensions / source / propctrlr / handlerhelper.hxx
blob555b8ee825e8a42b2587eee5e726d663df80302e
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 #pragma once
22 #include <com/sun/star/beans/Property.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/script/XTypeConverter.hpp>
25 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/beans/Optional.hpp>
28 #include <unotools/resmgr.hxx>
30 #include <memory>
31 #include <vector>
33 namespace weld { class Builder; class Widget; class Window; }
34 namespace com::sun::star {
35 namespace inspection {
36 struct LineDescriptor;
40 namespace pcr
44 //= PropertyHandlerHelper
46 class PropertyHandlerHelper
48 public:
49 /** helper for implementing XPropertyHandler::describePropertyLine in a generic way
51 static void describePropertyLine(
52 const css::beans::Property& _rProperty,
53 css::inspection::LineDescriptor& /* [out] */ _out_rDescriptor,
54 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory
57 /** helper for implementing XPropertyHandler::convertToPropertyValue
59 static css::uno::Any convertToPropertyValue(
60 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
61 const css::uno::Reference< css::script::XTypeConverter >& _rxTypeConverter,
62 const css::beans::Property& _rProperty,
63 const css::uno::Any& _rControlValue
66 /// helper for implementing XPropertyHandler::convertToControlValue
67 static css::uno::Any convertToControlValue(
68 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
69 const css::uno::Reference< css::script::XTypeConverter >& _rxTypeConverter,
70 const css::uno::Any& _rPropertyValue,
71 const css::uno::Type& _rControlValueType
74 /** creates an <member scope="css::inspection">PropertyControlType::ListBox</member>-type control
75 and fills it with initial values
77 @param _rxControlFactory
78 A control factory. Must not be <NULL/>.
80 @param _rInitialListEntries
81 the initial values of the control
83 @param _bReadOnlyControl
84 determines whether the control should be read-only
86 @param _bSorted
87 determines whether the list entries should be sorted
89 @return
90 the newly created control
92 static css::uno::Reference< css::inspection::XPropertyControl >
93 createListBoxControl(
94 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
95 std::vector< OUString >&& _rInitialListEntries,
96 bool _bReadOnlyControl,
97 bool _bSorted
100 /** creates an <member scope="css::inspection">PropertyControlType::ListBox</member>-type control
101 and fills it with initial values.
103 @param _rxControlFactory
104 A control factory. Must not be <NULL/>.
106 @param pTransIds
107 the initial translation ids for the value of the control
109 @param nElements
110 the count of initial values of the control
112 @param _bReadOnlyControl
113 determines whether the control should be read-only
115 @return
116 the newly created control
118 static css::uno::Reference< css::inspection::XPropertyControl >
119 createListBoxControl(
120 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
121 const TranslateId* pTransIds, size_t nElements,
122 bool _bReadOnlyControl
125 /** creates an <member scope="css::inspection">PropertyControlType::ComboBox</member>-type control
126 and fills it with initial values
128 @param _rxControlFactory
129 A control factory. Must not be <NULL/>.
131 @param _rInitialListEntries
132 the initial values of the control
134 @param _bSorted
135 determines whether the list entries should be sorted
137 @return
138 the newly created control
140 static css::uno::Reference< css::inspection::XPropertyControl >
141 createComboBoxControl(
142 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
143 std::vector< OUString >&& _rInitialListEntries,
144 bool _bSorted
147 /** creates an <member scope="css::inspection">PropertyControlType::NumericField</member>-type control
148 and initializes it
150 @param _rxControlFactory
151 A control factory. Must not be <NULL/>.
152 @param _nDigits
153 number of decimal digits for the control
154 (<member scope="css::inspection">XNumericControl::DecimalDigits</member>)
155 @param _rMinValue
156 minimum value which can be entered in the control
157 (<member scope="css::inspection">XNumericControl::MinValue</member>)
158 @param _rMaxValue
159 maximum value which can be entered in the control
160 (<member scope="css::inspection">XNumericControl::MaxValue</member>)
162 @return
163 the newly created control
165 static css::uno::Reference< css::inspection::XPropertyControl >
166 createNumericControl(
167 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
168 sal_Int16 _nDigits,
169 const css::beans::Optional< double >& _rMinValue,
170 const css::beans::Optional< double >& _rMaxValue
173 /** marks the document passed in our UNO context as modified
175 The method looks up a value called "ContextDocument" in the given UNO component context,
176 queries it for the ->css::util::XModifiable interface, and calls its
177 setModified method. If either of those steps fails, this is asserted in a non-product
178 version, and silently ignore otherwise.
180 @param _rContext
181 the component context which was used to create the component calling this method
183 static void setContextDocumentModified(
184 const css::uno::Reference< css::uno::XComponentContext > & _rContext
187 static css::uno::Reference< css::uno::XInterface > getContextDocument( const css::uno::Reference<css::uno::XComponentContext> & _rContext );
189 /// @throws css::uno::RuntimeException
190 static css::uno::Reference< css::uno::XInterface > getContextDocument_throw( const css::uno::Reference<css::uno::XComponentContext> & _rContext );
192 /** gets the window of the ObjectInspector in which a property handler lives
194 The method looks up a value called "DialogParentWindow" in the given UNO component context,
195 queries it for XWindow, and returns the respective weld::Window*. If either of those steps fails,
196 this is asserted in a non-product version, and silently ignore otherwise.
198 @param _rContext
199 the component context which was used to create the component calling this method
201 static weld::Window* getDialogParentFrame( const css::uno::Reference< css::uno::XComponentContext > & _rContext );
204 /** determines whether given PropertyAttributes require a to-be-created
205 <type scope="css::inspection">XPropertyControl</type> to be read-only
207 @param _nPropertyAttributes
208 the attributes of the property which should be reflected by a to-be-created
209 <type scope="css::inspection">XPropertyControl</type>
211 static bool requiresReadOnlyControl( sal_Int16 _nPropertyAttributes )
213 return ( _nPropertyAttributes & css::beans::PropertyAttribute::READONLY ) != 0;
216 static std::unique_ptr<weld::Builder> makeBuilder(const OUString& rUIFile, const css::uno::Reference<css::uno::XComponentContext>& rContext);
218 static void setBuilderParent(const css::uno::Reference<css::uno::XComponentContext>& rContext, weld::Widget* pParent);
220 static void clearBuilderParent(const css::uno::Reference<css::uno::XComponentContext>& rContext);
222 private:
223 PropertyHandlerHelper( const PropertyHandlerHelper& ) = delete;
224 PropertyHandlerHelper& operator=( const PropertyHandlerHelper& ) = delete;
228 } // namespace pcr
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */