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_dbaxml.hxx"
26 #ifndef DBA_XMLHELPER_HXX
27 #include "xmlHelper.hxx"
28 #endif
29 #ifndef _XMLOFF_XMLNMSPE_HXX
30 #include <xmloff/xmlnmspe.hxx>
31 #endif
32 #ifndef _XMLOFF_XMLTOKEN_HXX
33 #include <xmloff/xmltoken.hxx>
34 #endif
35 #ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
36 #include <com/sun/star/awt/TextAlign.hpp>
37 #endif
38 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
39 #include "xmlstrings.hrc"
40 #endif
41 #ifndef DBA_XMLENUMS_HXX
42 #include "xmlEnums.hxx"
43 #endif
44 #ifndef _XMLOFF_CONTEXTID_HXX_
45 #include <xmloff/contextid.hxx>
46 #endif
47 #ifndef _XMLOFF_XMLCONSTANTSPROPERTYHANDLER_HXX
48 #include <xmloff/XMLConstantsPropertyHandler.hxx>
49 #endif
50 #ifndef _XMLOFF_XMLEMENT_HXX
51 #include <xmloff/xmlement.hxx>
52 #endif
53 #ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
54 #include <com/sun/star/awt/TextAlign.hpp>
55 #endif
56 #ifndef _TOOLS_DEBUG_HXX
57 #include <tools/debug.hxx>
58 #endif
59 
60 namespace dbaxml
61 {
62 	using namespace ::xmloff::token;
63 	using namespace ::com::sun::star::awt;
DBG_NAME(OPropertyHandlerFactory)64 DBG_NAME(OPropertyHandlerFactory)
65 
66 OPropertyHandlerFactory::OPropertyHandlerFactory()
67 {
68     DBG_CTOR(OPropertyHandlerFactory,NULL);
69 
70 }
71 // -----------------------------------------------------------------------------
~OPropertyHandlerFactory()72 OPropertyHandlerFactory::~OPropertyHandlerFactory()
73 {
74 
75     DBG_DTOR(OPropertyHandlerFactory,NULL);
76 }
77 // -----------------------------------------------------------------------------
GetPropertyHandler(sal_Int32 _nType) const78 const XMLPropertyHandler* OPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
79 {
80 	const XMLPropertyHandler* pHandler = NULL;
81 
82 	switch (_nType)
83 	{
84 		case XML_DB_TYPE_EQUAL:
85 			if ( !m_pDisplayHandler.get() )
86 			{
87 				static SvXMLEnumMapEntry aDisplayMap[] =
88 				{
89 					{ XML_VISIBLE,		sal_True },
90 					{ XML_COLLAPSE,		sal_False },
91 					{ XML_TOKEN_INVALID, 0 }
92 				};
93 				m_pDisplayHandler.reset(new XMLConstantsPropertyHandler(aDisplayMap, XML_TOKEN_INVALID ));
94 			}
95 			pHandler = m_pDisplayHandler.get();
96 			break;
97 	}
98 	if ( !pHandler )
99 		pHandler = OControlPropertyHandlerFactory::GetPropertyHandler(_nType);
100 	return pHandler;
101 }
102 // -----------------------------------------------------------------------------
103 #define MAP_CONST( name, prefix, token, type, context )  { name.ascii, name.length,	prefix, token, type|XML_TYPE_PROP_TABLE, context, SvtSaveOptions::ODFVER_010 }
104 #define MAP_CONST_ASCII( name, prefix, token, type, context )  { name, sizeof(name)-1,	prefix, token, type|XML_TYPE_PROP_TABLE, context, SvtSaveOptions::ODFVER_010 }
105 #define MAP_END() { NULL, 0, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFVER_010}
106 // -----------------------------------------------------------------------------
GetTableStylesPropertySetMapper()107 UniReference < XMLPropertySetMapper > OXMLHelper::GetTableStylesPropertySetMapper()
108 {
109 	static const XMLPropertyMapEntry s_aTableStylesProperties[] =
110 	{
111 		//MAP_CONST( PROPERTY_FONTNAME,			XML_NAMESPACE_STYLE,	XML_FONT_NAME,   			XML_TYPE_STRING, 0 ),
112 		//MAP_CONST( PROPERTY_TEXTCOLOR,			XML_NAMESPACE_FO,		XML_COLOR,					XML_TYPE_COLOR, 0 ),
113 		//MAP_CONST( PROPERTY_TEXTLINECOLOR,		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,	XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ),
114 
115 		//MAP_CONST( PROPERTY_TEXTRELIEF,			XML_NAMESPACE_STYLE,	XML_FONT_RELIEF,			    XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY, 0 ),
116 		//MAP_CONST( PROPERTY_TEXTEMPHASIS,		XML_NAMESPACE_STYLE,	XML_TEXT_EMPHASIZE, 		    XML_TYPE_CONTROL_TEXT_EMPHASIZE, 0 ),
117 		//MAP_CONST( PROPERTY_FONTCHARWIDTH,		XML_NAMESPACE_STYLE,	XML_FONT_CHAR_WIDTH,		    XML_TYPE_NUMBER16, 0 ),
118 		//MAP_CONST( PROPERTY_FONTCHARSET,		XML_NAMESPACE_STYLE,	XML_FONT_CHARSET,			    XML_TYPE_TEXT_FONTENCODING, 0 ),
119 		//MAP_CONST( PROPERTY_FONTFAMILY,			XML_NAMESPACE_STYLE,	XML_FONT_FAMILY_GENERIC,	    XML_TYPE_TEXT_FONTFAMILY, 0 ),
120 		//MAP_CONST( PROPERTY_FONTHEIGHT,			XML_NAMESPACE_FO,		XML_FONT_SIZE,				    XML_TYPE_MEASURE16, 0 ),
121 		//MAP_CONST( PROPERTY_FONTKERNING,		XML_NAMESPACE_STYLE,	XML_LETTER_KERNING, 		    XML_TYPE_BOOL, 0 ),
122 		//
123 		//MAP_CONST( PROPERTY_FONTORIENTATION,	XML_NAMESPACE_STYLE,	XML_ROTATION_ANGLE, 		    XML_TYPE_ROTATION_ANGLE, 0 ),
124 		//MAP_CONST( PROPERTY_FONTPITCH,			XML_NAMESPACE_STYLE,	XML_FONT_PITCH, 			    XML_TYPE_TEXT_FONTPITCH, 0 ),
125 		//MAP_CONST( PROPERTY_FONTSLANT,			XML_NAMESPACE_FO,		XML_FONT_STYLE, 			    XML_TYPE_TEXT_POSTURE, 0 ),
126 		//MAP_CONST_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_STYLE, 	XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY,	0),
127 		//MAP_CONST_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_TYPE, 	XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY,	0),
128 		//MAP_CONST_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_WIDTH, 	XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY,	0),
129 		//MAP_CONST_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_TEXT, 	XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY,	0),
130 		//MAP_CONST( PROPERTY_FONTSTYLENAME,		XML_NAMESPACE_STYLE,	XML_FONT_STYLE_NAME,		    XML_TYPE_STRING, 0 ),
131 		//MAP_CONST_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_STYLE,		XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ),
132 		//MAP_CONST_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_TYPE,		XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ),
133 		//MAP_CONST_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_WIDTH,		XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ),
134 		//MAP_CONST_ASCII( "CharUnderlineColor",	XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,		XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0	),
135 		//MAP_CONST_ASCII( "CharUnderlineHasColor",XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,		XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, 0	),
136 		//MAP_CONST( PROPERTY_FONTWEIGHT,			XML_NAMESPACE_FO,		XML_FONT_WEIGHT,			    XML_TYPE_TEXT_WEIGHT, 0 ),
137 		//MAP_CONST( PROPERTY_FONTWIDTH,			XML_NAMESPACE_STYLE,	XML_FONT_WIDTH, 			    XML_TYPE_FONT_WIDTH, 0 ),
138 		//MAP_CONST( PROPERTY_FONTWORDLINEMODE,	XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_MODE,		XML_TYPE_TEXT_LINE_MODE, 0 ),
139 		MAP_END()
140 	};
141 	UniReference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
142 	return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aTableStylesProperties, xFac);
143 }
144 // -----------------------------------------------------------------------------
GetColumnStylesPropertySetMapper()145 UniReference < XMLPropertySetMapper > OXMLHelper::GetColumnStylesPropertySetMapper()
146 {
147 #define MAP_CONST_COLUMN( name, prefix, token, type, context )  { name.ascii, name.length,	prefix, token, static_cast<sal_Int32>(type|XML_TYPE_PROP_TABLE_COLUMN), context, SvtSaveOptions::ODFVER_010 }
148 	static const XMLPropertyMapEntry s_aColumnStylesProperties[] =
149 	{
150 		MAP_CONST_COLUMN( PROPERTY_WIDTH,			XML_NAMESPACE_STYLE,	XML_COLUMN_WIDTH,		XML_TYPE_MEASURE, 0),
151 		MAP_CONST_COLUMN( PROPERTY_HIDDEN,			XML_NAMESPACE_TABLE,	XML_DISPLAY,			XML_DB_TYPE_EQUAL|MID_FLAG_SPECIAL_ITEM, CTF_DB_ISVISIBLE ),
152 		MAP_CONST_COLUMN( PROPERTY_NUMBERFORMAT,	XML_NAMESPACE_STYLE,	XML_DATA_STYLE_NAME,	XML_TYPE_NUMBER|MID_FLAG_SPECIAL_ITEM, CTF_DB_NUMBERFORMAT),
153 		MAP_END()
154 	};
155 	UniReference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory();
156 	return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aColumnStylesProperties, xFac);
157 }
158 // -----------------------------------------------------------------------------
GetCellStylesPropertySetMapper()159 UniReference < XMLPropertySetMapper > OXMLHelper::GetCellStylesPropertySetMapper()
160 {
161 #define MAP_CONST_CELL( name, prefix, token, type, context )  { name.ascii, name.length,	prefix, token, type|XML_TYPE_PROP_PARAGRAPH, context, SvtSaveOptions::ODFVER_010 }
162 #define MAP_CONST_TEXT( name, prefix, token, type, context )  { name.ascii, name.length,	prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFVER_010 }
163 #define MAP_CONST_TEXT_ASCII( name, prefix, token, type, context ) { name, sizeof(name)-1,	prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFVER_010 }
164 	static const XMLPropertyMapEntry s_aCellStylesProperties[] =
165 	{
166 		MAP_CONST_CELL( PROPERTY_ALIGN,			    XML_NAMESPACE_FO,	    XML_TEXT_ALIGN,			    XML_TYPE_TEXT_ALIGN, CTF_DB_COLUMN_TEXT_ALIGN),
167         MAP_CONST_TEXT( PROPERTY_FONTNAME,			XML_NAMESPACE_STYLE,	XML_FONT_NAME,   			XML_TYPE_STRING, 0 ),
168 		MAP_CONST_TEXT( PROPERTY_TEXTCOLOR,			XML_NAMESPACE_FO,		XML_COLOR,					XML_TYPE_COLOR, 0 ),
169 		MAP_CONST_TEXT( PROPERTY_TEXTLINECOLOR,		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,	XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ),
170 
171 		MAP_CONST_TEXT( PROPERTY_TEXTRELIEF,		XML_NAMESPACE_STYLE,	XML_FONT_RELIEF,			    XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY, 0 ),
172 		MAP_CONST_TEXT( PROPERTY_TEXTEMPHASIS,		XML_NAMESPACE_STYLE,	XML_TEXT_EMPHASIZE, 		    XML_TYPE_CONTROL_TEXT_EMPHASIZE, 0 ),
173 		MAP_CONST_TEXT( PROPERTY_FONTCHARWIDTH,		XML_NAMESPACE_STYLE,	XML_FONT_CHAR_WIDTH,		    XML_TYPE_NUMBER16, 0 ),
174 		MAP_CONST_TEXT( PROPERTY_FONTCHARSET,		XML_NAMESPACE_STYLE,	XML_FONT_CHARSET,			    XML_TYPE_TEXT_FONTENCODING, 0 ),
175 		MAP_CONST_TEXT( PROPERTY_FONTFAMILY,		XML_NAMESPACE_STYLE,	XML_FONT_FAMILY_GENERIC,	    XML_TYPE_TEXT_FONTFAMILY, 0 ),
176 		MAP_CONST_TEXT( PROPERTY_FONTHEIGHT,		XML_NAMESPACE_FO,		XML_FONT_SIZE,				    XML_TYPE_MEASURE16, 0 ),
177 		MAP_CONST_TEXT( PROPERTY_FONTKERNING,		XML_NAMESPACE_STYLE,	XML_LETTER_KERNING, 		    XML_TYPE_BOOL, 0 ),
178 
179 		MAP_CONST_TEXT( PROPERTY_FONTORIENTATION,	XML_NAMESPACE_STYLE,	XML_ROTATION_ANGLE, 		    XML_TYPE_ROTATION_ANGLE, 0 ),
180 		MAP_CONST_TEXT( PROPERTY_FONTPITCH,			XML_NAMESPACE_STYLE,	XML_FONT_PITCH, 			    XML_TYPE_TEXT_FONTPITCH, 0 ),
181 		MAP_CONST_TEXT( PROPERTY_FONTSLANT,			XML_NAMESPACE_FO,		XML_FONT_STYLE, 			    XML_TYPE_TEXT_POSTURE, 0 ),
182 		MAP_CONST_TEXT_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_STYLE, 	XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY,	0),
183 		MAP_CONST_TEXT_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_TYPE, 	XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY,	0),
184 		MAP_CONST_TEXT_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_WIDTH, 	XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY,	0),
185 		MAP_CONST_TEXT_ASCII( "CharStrikeout",		XML_NAMESPACE_STYLE,	XML_TEXT_LINE_THROUGH_TEXT, 	XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY,	0),
186 		MAP_CONST_TEXT( PROPERTY_FONTSTYLENAME,		XML_NAMESPACE_STYLE,	XML_FONT_STYLE_NAME,		    XML_TYPE_STRING, 0 ),
187 		MAP_CONST_TEXT_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_STYLE,		XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ),
188 		MAP_CONST_TEXT_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_TYPE,		XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ),
189 		MAP_CONST_TEXT_ASCII( "CharUnderline",		XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_WIDTH,		XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ),
190 		MAP_CONST_TEXT_ASCII( "CharUnderlineColor",	XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,		XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0	),
191 		MAP_CONST_TEXT_ASCII( "CharUnderlineHasColor",XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_COLOR,		XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, 0	),
192 		MAP_CONST_TEXT( PROPERTY_FONTWEIGHT,		XML_NAMESPACE_FO,		XML_FONT_WEIGHT,			    XML_TYPE_TEXT_WEIGHT, 0 ),
193 		MAP_CONST_TEXT( PROPERTY_FONTWIDTH,			XML_NAMESPACE_STYLE,	XML_FONT_WIDTH, 			    XML_TYPE_FONT_WIDTH, 0 ),
194 		MAP_CONST_TEXT( PROPERTY_FONTWORDLINEMODE,	XML_NAMESPACE_STYLE,	XML_TEXT_UNDERLINE_MODE,		XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ),
195 		MAP_END()
196 	};
197 	UniReference < XMLPropertyHandlerFactory> xFac = new /*OPropertyHandlerFactory*/::xmloff::OControlPropertyHandlerFactory();
198 	return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aCellStylesProperties, xFac);
199 }
200 // -----------------------------------------------------------------------------
GetRowStylesPropertySetMapper()201 UniReference < XMLPropertySetMapper > OXMLHelper::GetRowStylesPropertySetMapper()
202 {
203 #define MAP_CONST_ROW( name, prefix, token, type, context )  { name.ascii, name.length,	prefix, token, type|XML_TYPE_PROP_TABLE_ROW, context, SvtSaveOptions::ODFVER_010 }
204 	static const XMLPropertyMapEntry s_aStylesProperties[] =
205 	{
206 		MAP_CONST_ROW( PROPERTY_ROW_HEIGHT,			XML_NAMESPACE_STYLE,	XML_ROW_HEIGHT,				XML_TYPE_MEASURE, 0),
207 		MAP_END()
208 	};
209 	UniReference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory();
210 	return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aStylesProperties, xFac);
211 }
212 // -----------------------------------------------------------------------------
213 }
214 
215