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