1*05236b1aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*05236b1aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*05236b1aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*05236b1aSAndrew Rist  * distributed with this work for additional information
6*05236b1aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*05236b1aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*05236b1aSAndrew Rist  * "License"); you may not use this file except in compliance
9*05236b1aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*05236b1aSAndrew Rist  *
11*05236b1aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*05236b1aSAndrew Rist  *
13*05236b1aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*05236b1aSAndrew Rist  * software distributed under the License is distributed on an
15*05236b1aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*05236b1aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*05236b1aSAndrew Rist  * specific language governing permissions and limitations
18*05236b1aSAndrew Rist  * under the License.
19*05236b1aSAndrew Rist  *
20*05236b1aSAndrew Rist  *************************************************************/
21*05236b1aSAndrew Rist 
22*05236b1aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "common.hxx"
25cdf0e10cSrcweir #include "misc.hxx"
26cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx>
27cdf0e10cSrcweir #include <xmlscript/xml_helper.hxx>
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/FontEmphasisMark.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/FontRelief.hpp>
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace css = ::com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace xmlscript
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir struct Style
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     sal_uInt32 _backgroundColor;
46cdf0e10cSrcweir     sal_uInt32 _textColor;
47cdf0e10cSrcweir     sal_uInt32 _textLineColor;
48cdf0e10cSrcweir     sal_Int16 _border;
49cdf0e10cSrcweir     sal_Int32 _borderColor;
50cdf0e10cSrcweir     css::awt::FontDescriptor _descr;
51cdf0e10cSrcweir     sal_uInt16 _fontRelief;
52cdf0e10cSrcweir     sal_uInt16 _fontEmphasisMark;
53cdf0e10cSrcweir     sal_uInt32 _fillColor;
54cdf0e10cSrcweir     sal_Int16 _visualEffect;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     // current highest mask: 0x40
57cdf0e10cSrcweir     short _all;
58cdf0e10cSrcweir     short _set;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     ::rtl::OUString _id;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     inline Style( short all_ ) SAL_THROW( () )
63cdf0e10cSrcweir         : _fontRelief( css::awt::FontRelief::NONE )
64cdf0e10cSrcweir         , _fontEmphasisMark( css::awt::FontEmphasisMark::NONE )
65cdf0e10cSrcweir         , _all( all_ )
66cdf0e10cSrcweir         , _set( 0 )
67cdf0e10cSrcweir         {}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     css::uno::Reference< css::xml::sax::XAttributeList > createElement();
70cdf0e10cSrcweir };
71cdf0e10cSrcweir class StyleBag
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     ::std::vector< Style * > _styles;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir public:
76cdf0e10cSrcweir     ~StyleBag() SAL_THROW( () );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     ::rtl::OUString getStyleId( Style const & rStyle ) SAL_THROW( () );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     void dump( css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >
81cdf0e10cSrcweir                const & xOut );
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir class ElementDescriptor
85cdf0e10cSrcweir     : public ::xmlscript::XMLElement
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertySet > _xProps;
88cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertyState > _xPropState;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir public:
ElementDescriptor(css::uno::Reference<css::beans::XPropertySet> const & xProps,css::uno::Reference<css::beans::XPropertyState> const & xPropState,::rtl::OUString const & name)91cdf0e10cSrcweir     inline ElementDescriptor(
92cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertySet > const & xProps,
93cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyState > const & xPropState,
94cdf0e10cSrcweir         ::rtl::OUString const & name )
95cdf0e10cSrcweir         SAL_THROW( () )
96cdf0e10cSrcweir         : XMLElement( name )
97cdf0e10cSrcweir         , _xProps( xProps )
98cdf0e10cSrcweir         , _xPropState( xPropState )
99cdf0e10cSrcweir         {}
100cdf0e10cSrcweir     inline ElementDescriptor(
101cdf0e10cSrcweir         ::rtl::OUString const & name )
102cdf0e10cSrcweir         SAL_THROW( () )
103cdf0e10cSrcweir         : XMLElement( name )
104cdf0e10cSrcweir         {}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     template<typename T>
107cdf0e10cSrcweir     inline void read(
108cdf0e10cSrcweir         ::rtl::OUString const & propName, ::rtl::OUString const & attrName,
109cdf0e10cSrcweir         bool forceAttribute = false );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     //
112cdf0e10cSrcweir     template<typename T>
113cdf0e10cSrcweir     inline bool readProp( T * ret, ::rtl::OUString const & rPropName );
114cdf0e10cSrcweir     css::uno::Any readProp( ::rtl::OUString const & rPropName );
115cdf0e10cSrcweir     //
116cdf0e10cSrcweir     void readDefaults( bool supportPrintable = true, bool supportVisible = true );
117cdf0e10cSrcweir     //
118cdf0e10cSrcweir     void readStringAttr(
119cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
readDoubleAttr(::rtl::OUString const & rPropName,::rtl::OUString const & rAttrName)120cdf0e10cSrcweir     inline void readDoubleAttr(
121cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName )
122cdf0e10cSrcweir         { read<double>( rPropName, rAttrName ); }
readLongAttr(::rtl::OUString const & rPropName,::rtl::OUString const & rAttrName,bool forceAttribute=false)123cdf0e10cSrcweir     inline void readLongAttr(
124cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName,
125cdf0e10cSrcweir         bool forceAttribute = false )
126cdf0e10cSrcweir         { read<sal_Int32>( rPropName, rAttrName, forceAttribute ); }
127cdf0e10cSrcweir     void readHexLongAttr(
128cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
readShortAttr(::rtl::OUString const & rPropName,::rtl::OUString const & rAttrName)129cdf0e10cSrcweir     inline void readShortAttr(
130cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName )
131cdf0e10cSrcweir         { read<sal_Int32>( rPropName, rAttrName ); }
readBoolAttr(::rtl::OUString const & rPropName,::rtl::OUString const & rAttrName)132cdf0e10cSrcweir     inline void readBoolAttr(
133cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName )
134cdf0e10cSrcweir         { read<sal_Bool>( rPropName, rAttrName ); }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     void readAlignAttr(
137cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
138cdf0e10cSrcweir     void readVerticalAlignAttr(
139cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
140cdf0e10cSrcweir     void readImageAlignAttr(
141cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
142cdf0e10cSrcweir     void readImagePositionAttr(
143cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
144cdf0e10cSrcweir     void readDateFormatAttr(
145cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
146cdf0e10cSrcweir     void readTimeFormatAttr(
147cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
148cdf0e10cSrcweir     void readOrientationAttr(
149cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
150cdf0e10cSrcweir     void readButtonTypeAttr(
151cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
152cdf0e10cSrcweir     void readLineEndFormatAttr(
153cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
154cdf0e10cSrcweir 	void readSelectionTypeAttr(
155cdf0e10cSrcweir         ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName );
156cdf0e10cSrcweir 	//
addBoolAttr(::rtl::OUString const & rAttrName,sal_Bool bValue)157cdf0e10cSrcweir     inline void addBoolAttr(
158cdf0e10cSrcweir         ::rtl::OUString const & rAttrName, sal_Bool bValue )
159cdf0e10cSrcweir         { addAttribute( rAttrName, ::rtl::OUString::valueOf(bValue) ); }
160cdf0e10cSrcweir     void addNumberFormatAttr(
161cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertySet >
162cdf0e10cSrcweir         const & xFormatProperties,
163cdf0e10cSrcweir         ::rtl::OUString const & rAttrName );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     //
166cdf0e10cSrcweir     void readEvents() SAL_THROW( (css::uno::Exception) );
167cdf0e10cSrcweir     //
168cdf0e10cSrcweir     void readDialogModel( StyleBag * all_styles )
169cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
170cdf0e10cSrcweir     void readButtonModel( StyleBag * all_styles )
171cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
172cdf0e10cSrcweir     void readEditModel( StyleBag * all_styles )
173cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
174cdf0e10cSrcweir     void readCheckBoxModel( StyleBag * all_styles )
175cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
176cdf0e10cSrcweir     void readRadioButtonModel( StyleBag * all_styles )
177cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
178cdf0e10cSrcweir     void readComboBoxModel( StyleBag * all_styles )
179cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
180cdf0e10cSrcweir     void readCurrencyFieldModel( StyleBag * all_styles )
181cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
182cdf0e10cSrcweir     void readDateFieldModel( StyleBag * all_styles )
183cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
184cdf0e10cSrcweir     void readFileControlModel( StyleBag * all_styles )
185cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
186cdf0e10cSrcweir 	void readTreeControlModel( StyleBag * all_styles )
187cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
188cdf0e10cSrcweir     void readFixedTextModel( StyleBag * all_styles )
189cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
190cdf0e10cSrcweir     void readGroupBoxModel( StyleBag * all_styles )
191cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
192cdf0e10cSrcweir     void readImageControlModel( StyleBag * all_styles )
193cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
194cdf0e10cSrcweir     void readListBoxModel( StyleBag * all_styles )
195cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
196cdf0e10cSrcweir     void readNumericFieldModel( StyleBag * all_styles )
197cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
198cdf0e10cSrcweir     void readPatternFieldModel( StyleBag * all_styles )
199cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
200cdf0e10cSrcweir     void readFormattedFieldModel( StyleBag * all_styles )
201cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
202cdf0e10cSrcweir     void readTimeFieldModel( StyleBag * all_styles )
203cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
204cdf0e10cSrcweir     void readFixedLineModel( StyleBag * all_styles )
205cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
206cdf0e10cSrcweir     void readProgressBarModel( StyleBag * all_styles )
207cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
208cdf0e10cSrcweir     void readScrollBarModel( StyleBag * all_styles )
209cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
210cdf0e10cSrcweir 	void readFixedHyperLinkModel( StyleBag * all_styles )
211cdf0e10cSrcweir         SAL_THROW( (css::uno::Exception) );
212cdf0e10cSrcweir };
213cdf0e10cSrcweir 
214cdf0e10cSrcweir template<typename T>
read(::rtl::OUString const & propName,::rtl::OUString const & attrName,bool forceAttribute)215cdf0e10cSrcweir inline void ElementDescriptor::read(
216cdf0e10cSrcweir     ::rtl::OUString const & propName, ::rtl::OUString const & attrName,
217cdf0e10cSrcweir     bool forceAttribute )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     if (forceAttribute ||
220cdf0e10cSrcweir         css::beans::PropertyState_DEFAULT_VALUE !=
221cdf0e10cSrcweir         _xPropState->getPropertyState( propName ))
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         css::uno::Any a( _xProps->getPropertyValue( propName ) );
224cdf0e10cSrcweir         T v = T();
225cdf0e10cSrcweir         if (a >>= v)
226cdf0e10cSrcweir             addAttribute( attrName, ::rtl::OUString::valueOf(v) );
227cdf0e10cSrcweir         else
228cdf0e10cSrcweir             OSL_ENSURE( 0, "### unexpected property type!" );
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir template<typename T>
readProp(T * ret,::rtl::OUString const & rPropName)233cdf0e10cSrcweir inline bool ElementDescriptor::readProp(
234cdf0e10cSrcweir     T * ret, ::rtl::OUString const & rPropName )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     _xProps->getPropertyValue( rPropName ) >>= *ret;
237cdf0e10cSrcweir     return css::beans::PropertyState_DEFAULT_VALUE !=
238cdf0e10cSrcweir         _xPropState->getPropertyState( rPropName );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir }
242