cid#1607171 Data race condition
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / exp_share.hxx
blob55a53bcc13b89c53efa2536525b343d7cda96593
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 <utility>
23 #include <xmlscript/xmldlg_imexp.hxx>
24 #include <xmlscript/xml_helper.hxx>
25 #include <osl/diagnose.h>
26 #include <com/sun/star/xml/sax/XAttributeList.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/beans/XPropertyState.hpp>
29 #include <com/sun/star/awt/FontDescriptor.hpp>
30 #include <com/sun/star/awt/FontEmphasisMark.hpp>
31 #include <com/sun/star/awt/FontRelief.hpp>
32 #include <memory>
33 #include <vector>
36 namespace xmlscript
39 struct Style
41 sal_uInt32 _backgroundColor;
42 sal_uInt32 _textColor;
43 sal_uInt32 _textLineColor;
44 sal_Int16 _border;
45 sal_Int32 _borderColor;
46 css::awt::FontDescriptor _descr;
47 sal_uInt16 _fontRelief;
48 sal_uInt16 _fontEmphasisMark;
49 sal_uInt32 _fillColor;
50 sal_Int16 _visualEffect;
52 // current highest mask: 0x40
53 short _all;
54 short _set;
56 OUString _id;
58 explicit Style( short all_ )
59 : _backgroundColor(0)
60 , _textColor(0)
61 , _textLineColor(0)
62 , _border(0)
63 , _borderColor(0)
64 , _fontRelief(css::awt::FontRelief::NONE)
65 , _fontEmphasisMark(css::awt::FontEmphasisMark::NONE)
66 , _fillColor(0)
67 , _visualEffect(0)
68 , _all(all_)
69 , _set(0)
73 css::uno::Reference< css::xml::sax::XAttributeList > createElement();
75 class StyleBag
77 ::std::vector<Style> _styles;
79 public:
80 ~StyleBag() ;
82 OUString getStyleId( Style const & rStyle );
84 void dump( css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >
85 const & xOut );
88 class ElementDescriptor
89 : public ::xmlscript::XMLElement
91 css::uno::Reference< css::beans::XPropertySet > _xProps;
92 css::uno::Reference< css::beans::XPropertyState > _xPropState;
93 css::uno::Reference< css::frame::XModel > _xDocument;
95 public:
96 ElementDescriptor(
97 css::uno::Reference< css::beans::XPropertySet > xProps,
98 css::uno::Reference< css::beans::XPropertyState > xPropState,
99 OUString const & name, css::uno::Reference< css::frame::XModel > xDocument )
100 : XMLElement( name )
101 , _xProps(std::move( xProps ))
102 , _xPropState(std::move( xPropState ))
103 , _xDocument(std::move( xDocument ))
105 explicit ElementDescriptor(
106 OUString const & name )
107 : XMLElement( name )
110 template<typename T>
111 inline void read(
112 OUString const & propName, OUString const & attrName,
113 bool forceAttribute = false );
115 template<typename T>
116 inline bool readProp( T * ret, OUString const & rPropName );
117 css::uno::Any readProp( OUString const & rPropName );
118 void readScrollableSettings();
119 void readDefaults( bool supportPrintable = true, bool supportVisible = true );
120 void readStringAttr(
121 OUString const & rPropName, OUString const & rAttrName );
122 void readDoubleAttr(
123 OUString const & rPropName, OUString const & rAttrName )
124 { read<double>( rPropName, rAttrName ); }
125 void readLongAttr(
126 OUString const & rPropName, OUString const & rAttrName,
127 bool forceAttribute = false )
128 { read<sal_Int32>( rPropName, rAttrName, forceAttribute ); }
129 void readHexLongAttr(
130 OUString const & rPropName, OUString const & rAttrName );
131 void readShortAttr(
132 OUString const & rPropName, OUString const & rAttrName )
133 { read<sal_Int32>( rPropName, rAttrName ); }
134 inline void readBoolAttr(
135 OUString const & rPropName, OUString const & rAttrName );
137 void readAlignAttr(
138 OUString const & rPropName, OUString const & rAttrName );
139 void readVerticalAlignAttr(
140 OUString const & rPropName, OUString const & rAttrName );
141 void readImageAlignAttr(
142 OUString const & rPropName, OUString const & rAttrName );
143 void readImagePositionAttr(
144 OUString const & rPropName, OUString const & rAttrName );
145 void readDateAttr(
146 OUString const & rPropName, OUString const & rAttrName );
147 void readDateFormatAttr(
148 OUString const & rPropName, OUString const & rAttrName );
149 void readTimeAttr(
150 OUString const & rPropName, OUString const & rAttrName );
151 void readTimeFormatAttr(
152 OUString const & rPropName, OUString const & rAttrName );
153 void readOrientationAttr(
154 OUString const & rPropName, OUString const & rAttrName );
155 void readButtonTypeAttr(
156 OUString const & rPropName, OUString const & rAttrName );
157 void readLineEndFormatAttr(
158 OUString const & rPropName, OUString const & rAttrName );
159 void readSelectionTypeAttr(
160 OUString const & rPropName, OUString const & rAttrName );
161 void readImageScaleModeAttr(
162 OUString const & rPropName, OUString const & rAttrName );
164 void readDataAwareAttr(OUString const & rAttrName );
165 void readImageOrGraphicAttr(OUString const & rAttrName );
167 void addBoolAttr(
168 OUString const & rAttrName, bool bValue )
169 { addAttribute( rAttrName, OUString::boolean(bValue) ); }
170 void addNumberFormatAttr(
171 css::uno::Reference< css::beans::XPropertySet >
172 const & xFormatProperties );
174 void readEvents();
175 void readDialogModel( StyleBag * all_styles );
176 void readBullitinBoard( StyleBag * all_styles );
177 void readMultiPageModel( StyleBag * all_styles );
178 void readFrameModel( StyleBag * all_styles );
179 void readPageModel( StyleBag * all_styles );
180 void readButtonModel( StyleBag * all_styles );
181 void readEditModel( StyleBag * all_styles );
182 void readCheckBoxModel( StyleBag * all_styles );
183 void readRadioButtonModel( StyleBag * all_styles );
184 void readComboBoxModel( StyleBag * all_styles );
185 void readCurrencyFieldModel( StyleBag * all_styles );
186 void readDateFieldModel( StyleBag * all_styles );
187 void readFileControlModel( StyleBag * all_styles );
188 void readTreeControlModel( StyleBag * all_styles );
189 void readFixedTextModel( StyleBag * all_styles );
190 void readGroupBoxModel( StyleBag * all_styles );
191 void readImageControlModel( StyleBag * all_styles );
192 void readListBoxModel( StyleBag * all_styles );
193 void readNumericFieldModel( StyleBag * all_styles );
194 void readPatternFieldModel( StyleBag * all_styles );
195 void readFormattedFieldModel( StyleBag * all_styles );
196 void readTimeFieldModel( StyleBag * all_styles );
197 void readFixedLineModel( StyleBag * all_styles );
198 void readProgressBarModel( StyleBag * all_styles );
199 void readScrollBarModel( StyleBag * all_styles );
200 void readSpinButtonModel( StyleBag * all_styles );
201 void readFixedHyperLinkModel( StyleBag * all_styles );
202 void readGridControlModel( StyleBag * all_styles );
205 template<typename T>
206 inline void ElementDescriptor::read(
207 OUString const & propName, OUString const & attrName,
208 bool forceAttribute )
210 if (forceAttribute ||
211 css::beans::PropertyState_DEFAULT_VALUE !=
212 _xPropState->getPropertyState( propName ))
214 css::uno::Any a( _xProps->getPropertyValue( propName ) );
215 T v = T();
216 if (a >>= v)
217 addAttribute( attrName, OUString::number(v) );
218 else
219 OSL_FAIL( "### unexpected property type!" );
223 template<>
224 inline void ElementDescriptor::read<sal_Bool>(
225 OUString const & propName, OUString const & attrName,
226 bool forceAttribute )
228 if (forceAttribute ||
229 css::beans::PropertyState_DEFAULT_VALUE !=
230 _xPropState->getPropertyState( propName ))
232 css::uno::Any a( _xProps->getPropertyValue( propName ) );
233 bool v;
234 if (a >>= v)
235 addAttribute( attrName, OUString::boolean(v) );
236 else
237 OSL_FAIL( "### unexpected property type!" );
241 inline void ElementDescriptor::readBoolAttr(
242 OUString const & rPropName, OUString const & rAttrName )
244 read<sal_Bool>( rPropName, rAttrName );
247 template<typename T>
248 inline bool ElementDescriptor::readProp(
249 T * ret, OUString const & rPropName )
251 _xProps->getPropertyValue( rPropName ) >>= *ret;
252 return css::beans::PropertyState_DEFAULT_VALUE !=
253 _xPropState->getPropertyState( rPropName );
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */