xref: /AOO41X/main/xmloff/source/forms/controlpropertymap.cxx (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "xmloff/xmlnmspe.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/maptype.hxx>
29 #include <xmloff/xmltypes.hxx>
30 #ifndef __SGI_STL_ALGORITHM
31 #include <algorithm>
32 #endif
33 #include "strings.hxx"
34 #include <xmloff/contextid.hxx>
35 #include "controlpropertymap.hxx"
36 
37 #include <string.h>
38 
39 using namespace ::xmloff::token;
40 
41 //.........................................................................
42 namespace xmloff
43 {
44 //.........................................................................
45 
46 #define MAP_ASCII( name, prefix, token, type, context )  { name, sizeof(name)-1, prefix, token, static_cast<sal_Int32>(type|XML_TYPE_PROP_TEXT), context, SvtSaveOptions::ODFVER_010 }
47 #define MAP_CONST( name, prefix, token, type, context )  { name.ascii, name.length, prefix, token, static_cast<sal_Int32>(type|XML_TYPE_PROP_TEXT), context, SvtSaveOptions::ODFVER_010 }
48 #define MAP_CONST_P( name, prefix, token, type, context )  { name.ascii, name.length,   prefix, token, static_cast<sal_Int32>(type|XML_TYPE_PROP_PARAGRAPH), context, SvtSaveOptions::ODFVER_010 }
49 #define MAP_END()   { NULL, 0, 0, XML_TOKEN_INVALID, 0, 0, SvtSaveOptions::ODFVER_010 }
50 
getControlStylePropertyMap_Access()51     XMLPropertyMapEntry* getControlStylePropertyMap_Access( )
52     {
53         static XMLPropertyMapEntry aControlStyleProperties[] =
54         {
55             MAP_CONST( PROPERTY_BACKGROUNDCOLOR, XML_NAMESPACE_FO,      XML_BACKGROUND_COLOR,       XML_TYPE_COLOR, 0 ),
56             MAP_CONST_P( PROPERTY_ALIGN,          XML_NAMESPACE_FO,       XML_TEXT_ALIGN,             XML_TYPE_TEXT_ALIGN, 0 ),
57             MAP_CONST( PROPERTY_BORDER,         XML_NAMESPACE_FO,       XML_BORDER,                 XML_TYPE_CONTROL_BORDER|MID_FLAG_MULTI_PROPERTY|MID_FLAG_MERGE_ATTRIBUTE, 0 ),
58             MAP_ASCII( "FontCharWidth",         XML_NAMESPACE_STYLE,    XML_FONT_CHAR_WIDTH,        XML_TYPE_NUMBER16, 0 ),
59             MAP_ASCII( "FontCharset",           XML_NAMESPACE_STYLE,    XML_FONT_CHARSET,           XML_TYPE_TEXT_FONTENCODING, 0 ),
60             MAP_ASCII( "FontFamily",            XML_NAMESPACE_STYLE,    XML_FONT_FAMILY_GENERIC,    XML_TYPE_TEXT_FONTFAMILY, 0 ),
61             MAP_ASCII( "FontHeight",            XML_NAMESPACE_FO,       XML_FONT_SIZE,              XML_TYPE_CHAR_HEIGHT, 0 ),
62             MAP_ASCII( "FontKerning",           XML_NAMESPACE_STYLE,    XML_LETTER_KERNING,         XML_TYPE_BOOL, 0 ),
63             MAP_ASCII( "FontName",              XML_NAMESPACE_STYLE,    XML_FONT_NAME,              XML_TYPE_STRING, 0 ),
64             MAP_ASCII( "FontOrientation",       XML_NAMESPACE_STYLE,    XML_ROTATION_ANGLE,         XML_TYPE_ROTATION_ANGLE, 0 ),
65             MAP_ASCII( "FontPitch",             XML_NAMESPACE_STYLE,    XML_FONT_PITCH,             XML_TYPE_TEXT_FONTPITCH, 0 ),
66             MAP_ASCII( "FontSlant",             XML_NAMESPACE_FO,       XML_FONT_STYLE,             XML_TYPE_TEXT_POSTURE, 0 ),
67 
68             MAP_ASCII( "FontStrikeout",         XML_NAMESPACE_STYLE,    XML_TEXT_LINE_THROUGH_STYLE,    XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0),
69             MAP_ASCII( "FontStrikeout",         XML_NAMESPACE_STYLE,    XML_TEXT_LINE_THROUGH_TYPE,     XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY,  0),
70             MAP_ASCII( "FontStrikeout",         XML_NAMESPACE_STYLE,    XML_TEXT_LINE_THROUGH_WIDTH,    XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY, 0),
71             MAP_ASCII( "FontStrikeout",         XML_NAMESPACE_STYLE,    XML_TEXT_LINE_THROUGH_TEXT,     XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY,  0),
72 
73             MAP_ASCII( "FontStyleName",         XML_NAMESPACE_STYLE,    XML_FONT_STYLE_NAME,        XML_TYPE_STRING, 0 ),
74             MAP_ASCII( "FontUnderline",         XML_NAMESPACE_STYLE,    XML_TEXT_UNDERLINE_STYLE,       XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ),
75             MAP_ASCII( "FontUnderline",         XML_NAMESPACE_STYLE,    XML_TEXT_UNDERLINE_TYPE,        XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ),
76             MAP_ASCII( "FontUnderline",         XML_NAMESPACE_STYLE,    XML_TEXT_UNDERLINE_WIDTH,       XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ),
77             MAP_ASCII( "FontWeight",            XML_NAMESPACE_FO,       XML_FONT_WEIGHT,            XML_TYPE_TEXT_WEIGHT, 0 ),
78             MAP_ASCII( "FontWidth",             XML_NAMESPACE_STYLE,    XML_FONT_WIDTH,             XML_TYPE_FONT_WIDTH, 0 ),
79             MAP_ASCII( "FontWordLineMode",      XML_NAMESPACE_FO,       XML_SCORE_SPACES,           XML_TYPE_NBOOL, 0 ),
80             MAP_ASCII( "SymbolColor",           XML_NAMESPACE_STYLE,    XML_COLOR,                  XML_TYPE_COLOR, 0 ),
81             MAP_ASCII( "BorderColor",           XML_NAMESPACE_FO,       XML_BORDER,                 XML_TYPE_CONTROL_BORDER_COLOR|MID_FLAG_MULTI_PROPERTY|MID_FLAG_MERGE_ATTRIBUTE, 0 ),
82             MAP_ASCII( "TextColor",             XML_NAMESPACE_FO,       XML_COLOR,                  XML_TYPE_COLOR, 0 ),
83             MAP_CONST( PROPERTY_FORMATKEY,      XML_NAMESPACE_STYLE,    XML_DATA_STYLE_NAME,        XML_TYPE_STRING | MID_FLAG_NO_PROPERTY_EXPORT | MID_FLAG_SPECIAL_ITEM, CTF_FORMS_DATA_STYLE ),
84             MAP_ASCII( "FontEmphasisMark",      XML_NAMESPACE_STYLE,    XML_TEXT_EMPHASIZE,         XML_TYPE_CONTROL_TEXT_EMPHASIZE, 0 ),
85             MAP_ASCII( "FontRelief",            XML_NAMESPACE_STYLE,    XML_FONT_RELIEF,            XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY, 0 ),
86             MAP_ASCII( "TextLineColor",         XML_NAMESPACE_STYLE,    XML_TEXT_UNDERLINE_COLOR,   XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ),
87             MAP_END()
88         };
89 
90         return aControlStyleProperties;
91     }
92 
getControlStylePropertyMap()93     const XMLPropertyMapEntry* getControlStylePropertyMap( )
94     {
95         return getControlStylePropertyMap_Access();
96     }
97 
98     //=====================================================================
99     //---------------------------------------------------------------------
100     struct XMLPropertyMapEntryLess
101     {
operator ()xmloff::XMLPropertyMapEntryLess102         sal_Bool operator()(const XMLPropertyMapEntry& _rLeft, const XMLPropertyMapEntry& _rRight)
103         {
104             return strcmp(_rLeft.msApiName, _rRight.msApiName) < 0;
105         }
106     };
107 
108     //---------------------------------------------------------------------
implSortMap(XMLPropertyMapEntry * _pMap)109     void implSortMap(XMLPropertyMapEntry* _pMap)
110     {
111         XMLPropertyMapEntry* pEnd;
112         // determine the last element
113         for ( pEnd = _pMap; pEnd->msApiName; ++pEnd)
114             ;
115         ::std::sort(_pMap, pEnd, XMLPropertyMapEntryLess());
116     }
117 
118     //---------------------------------------------------------------------
initializePropertyMaps()119     void initializePropertyMaps()
120     {
121         static sal_Bool bSorted = sal_False;
122         if (!bSorted)
123         {
124             implSortMap(getControlStylePropertyMap_Access());
125             bSorted = sal_True;
126         }
127     }
128 
129     //=====================================================================
130     //= OFormComponentStyleExportMapper
131     //=====================================================================
132     //---------------------------------------------------------------------
OFormComponentStyleExportMapper(const UniReference<XMLPropertySetMapper> & _rMapper)133     OFormComponentStyleExportMapper::OFormComponentStyleExportMapper( const UniReference< XMLPropertySetMapper >& _rMapper )
134         :SvXMLExportPropertyMapper( _rMapper )
135     {
136     }
137 
138     //---------------------------------------------------------------------
handleSpecialItem(SvXMLAttributeList & _rAttrList,const XMLPropertyState & _rProperty,const SvXMLUnitConverter & _rUnitConverter,const SvXMLNamespaceMap & _rNamespaceMap,const::std::vector<XMLPropertyState> * _pProperties,sal_uInt32 _nIdx) const139     void OFormComponentStyleExportMapper::handleSpecialItem( SvXMLAttributeList& _rAttrList, const XMLPropertyState& _rProperty, const SvXMLUnitConverter& _rUnitConverter,
140         const SvXMLNamespaceMap& _rNamespaceMap, const ::std::vector< XMLPropertyState >* _pProperties,
141         sal_uInt32 _nIdx ) const
142     {
143         // ignore the number style of grid columns - this is formatted elsewhere
144         if ( CTF_FORMS_DATA_STYLE != getPropertySetMapper()->GetEntryContextId( _rProperty.mnIndex ) )
145             SvXMLExportPropertyMapper::handleSpecialItem( _rAttrList, _rProperty, _rUnitConverter, _rNamespaceMap, _pProperties, _nIdx );
146     }
147 
148 //.........................................................................
149 }   // namespace xmloff
150 //.........................................................................
151 
152 
153