1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _XMLOFF_FORMATTRIBUTES_HXX_ 29 #define _XMLOFF_FORMATTRIBUTES_HXX_ 30 31 #include <com/sun/star/beans/XPropertySet.hpp> 32 #include <sal/types.h> 33 #include <vos/refernce.hxx> 34 #include <comphelper/stl_types.hxx> 35 36 class SvXMLExport; 37 struct SvXMLEnumMapEntry; 38 39 //......................................................................... 40 namespace xmloff 41 { 42 //......................................................................... 43 44 // flags for common control attributes 45 #define CCA_NAME 0x00000001 46 #define CCA_SERVICE_NAME 0x00000002 47 #define CCA_BUTTON_TYPE 0x00000004 48 #define CCA_CONTROL_ID 0x00000008 49 #define CCA_CURRENT_SELECTED 0x00000010 50 #define CCA_CURRENT_VALUE 0x00000020 51 #define CCA_DISABLED 0x00000040 52 #define CCA_DROPDOWN 0x00000080 53 #define CCA_FOR 0x00000100 54 #define CCA_IMAGE_DATA 0x00000200 55 #define CCA_LABEL 0x00000400 56 #define CCA_MAX_LENGTH 0x00000800 57 #define CCA_PRINTABLE 0x00001000 58 #define CCA_READONLY 0x00002000 59 #define CCA_SELECTED 0x00004000 60 #define CCA_SIZE 0x00008000 61 #define CCA_TAB_INDEX 0x00010000 62 #define CCA_TARGET_FRAME 0x00020000 63 #define CCA_TARGET_LOCATION 0x00040000 64 #define CCA_TAB_STOP 0x00080000 65 #define CCA_TITLE 0x00100000 66 #define CCA_VALUE 0x00200000 67 #define CCA_ORIENTATION 0x00400000 68 #define CCA_VISUAL_EFFECT 0x00800000 69 #define CCA_ENABLEVISIBLE 0x01000000 70 71 // flags for database control atttributes 72 #define DA_BOUND_COLUMN 0x00000001 73 #define DA_CONVERT_EMPTY 0x00000002 74 #define DA_DATA_FIELD 0x00000004 75 #define DA_LIST_SOURCE 0x00000008 76 #define DA_LIST_SOURCE_TYPE 0x00000010 77 #define DA_INPUT_REQUIRED 0x00000020 78 79 // flags for binding related control attributes 80 #define BA_LINKED_CELL 0x00000001 81 #define BA_LIST_LINKING_TYPE 0x00000002 82 #define BA_LIST_CELL_RANGE 0x00000004 83 #define BA_XFORMS_BIND 0x00000008 84 #define BA_XFORMS_LISTBIND 0x00000010 85 #define BA_XFORMS_SUBMISSION 0x00000020 86 87 // flags for event attributes 88 #define EA_CONTROL_EVENTS 0x00000001 89 #define EA_ON_CHANGE 0x00000002 90 #define EA_ON_CLICK 0x00000004 91 #define EA_ON_DBLCLICK 0x00000008 92 #define EA_ON_SELECT 0x00000010 93 94 /// attributes in the xml tag representing a form 95 enum FormAttributes 96 { 97 faName, 98 faServiceName, 99 faAction, 100 faEnctype, 101 faMethod, 102 faTargetFrame, 103 faAllowDeletes, 104 faAllowInserts, 105 faAllowUpdates, 106 faApplyFilter, 107 faCommand, 108 faCommandType, 109 faEscapeProcessing, 110 faDatasource, 111 faConnectionResource, 112 faDetailFiels, 113 faFilter, 114 faIgnoreResult, 115 faMasterFields, 116 faNavigationMode, 117 faOrder, 118 faTabbingCycle 119 }; 120 121 // any other attributes, which are special to some control types 122 #define SCA_ECHO_CHAR 0x00000001 123 #define SCA_MAX_VALUE 0x00000002 124 #define SCA_MIN_VALUE 0x00000004 125 #define SCA_VALIDATION 0x00000008 126 #define SCA_MULTI_LINE 0x00000020 127 #define SCA_AUTOMATIC_COMPLETION 0x00000080 128 #define SCA_MULTIPLE 0x00000100 129 #define SCA_DEFAULT_BUTTON 0x00000200 130 #define SCA_CURRENT_STATE 0x00000400 131 #define SCA_IS_TRISTATE 0x00000800 132 #define SCA_STATE 0x00001000 133 #define SCA_COLUMN_STYLE_NAME 0x00002000 134 #define SCA_STEP_SIZE 0x00004000 135 #define SCA_PAGE_STEP_SIZE 0x00008000 136 #define SCA_REPEAT_DELAY 0x00010000 137 #define SCA_TOGGLE 0x00020000 138 #define SCA_FOCUS_ON_CLICK 0x00040000 139 #define SCA_IMAGE_POSITION 0x00080000 140 141 // attributes of the office:forms element 142 enum OfficeFormsAttributes 143 { 144 ofaAutomaticFocus, 145 ofaApplyDesignMode 146 }; 147 148 //===================================================================== 149 //= OAttributeMetaData 150 //===================================================================== 151 /** allows the translation of attribute ids into strings. 152 153 <p>This class does not allow to connect xml attributes to property names or 154 something like that, it only deals with the xml side</p> 155 */ 156 class OAttributeMetaData 157 { 158 public: 159 /** calculates the xml attribute representation of a common control attribute. 160 @param _nId 161 the id of the attribute. Has to be one of the CCA_* constants. 162 */ 163 static const sal_Char* getCommonControlAttributeName(sal_Int32 _nId); 164 165 /** calculates the xml namespace key to use for a common control attribute 166 @param _nId 167 the id of the attribute. Has to be one of the CCA_* constants. 168 */ 169 static sal_uInt16 getCommonControlAttributeNamespace(sal_Int32 _nId); 170 171 /** retrieves the name of an attribute of a form xml representation 172 @param _eAttrib 173 enum value specifying the attribute 174 */ 175 static const sal_Char* getFormAttributeName(FormAttributes _eAttrib); 176 177 /** calculates the xml namespace key to use for a attribute of a form xml representation 178 @param _eAttrib 179 enum value specifying the attribute 180 */ 181 static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib); 182 183 /** calculates the xml attribute representation of a database attribute. 184 @param _nId 185 the id of the attribute. Has to be one of the DA_* constants. 186 */ 187 static const sal_Char* getDatabaseAttributeName(sal_Int32 _nId); 188 189 /** calculates the xml namespace key to use for a database attribute. 190 @param _nId 191 the id of the attribute. Has to be one of the DA_* constants. 192 */ 193 static sal_uInt16 getDatabaseAttributeNamespace(sal_Int32 _nId); 194 195 /** calculates the xml attribute representation of a special attribute. 196 @param _nId 197 the id of the attribute. Has to be one of the SCA_* constants. 198 */ 199 static const sal_Char* getSpecialAttributeName(sal_Int32 _nId); 200 201 /** calculates the xml attribute representation of a binding attribute. 202 @param _nId 203 the id of the attribute. Has to be one of the BA_* constants. 204 */ 205 static const sal_Char* getBindingAttributeName(sal_Int32 _nId); 206 207 /** calculates the xml namespace key to use for a binding attribute. 208 @param _nId 209 the id of the attribute. Has to be one of the BA_* constants. 210 */ 211 static sal_uInt16 getBindingAttributeNamespace(sal_Int32 _nId); 212 213 /** calculates the xml namespace key to use for a special attribute. 214 @param _nId 215 the id of the attribute. Has to be one of the SCA_* constants. 216 */ 217 static sal_uInt16 getSpecialAttributeNamespace(sal_Int32 _nId); 218 219 /** calculates the xml attribute representation of a attribute of the office:forms element 220 @param _nId 221 the id of the attribute 222 */ 223 static const sal_Char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib); 224 225 /** calculates the xml namedspace key of a attribute of the office:forms element 226 @param _nId 227 the id of the attribute 228 */ 229 static sal_uInt16 getOfficeFormsAttributeNamespace(OfficeFormsAttributes _eAttrib); 230 }; 231 232 //===================================================================== 233 //= OAttribute2Property 234 //===================================================================== 235 /** some kind of opposite to the OAttributeMetaData class. Able to translate 236 attributes into property names/types 237 238 <p>The construction of this class is rather expensive (or at least it's initialization from outside), 239 so it should be shared</p> 240 */ 241 class OAttribute2Property 242 { 243 public: 244 // TODO: maybe the following struct should be used for exports, too. In this case we would not need to 245 // store it's instances in a map, but in a vector for faster access. 246 struct AttributeAssignment 247 { 248 ::rtl::OUString sAttributeName; // the attribute name 249 ::rtl::OUString sPropertyName; // the property name 250 ::com::sun::star::uno::Type aPropertyType; // the property type 251 ::rtl::OUString sAttributeDefault; // the default if the attribute is not present 252 253 // entries which are special to some value types 254 const SvXMLEnumMapEntry* pEnumMap; // the enum map, if appliable 255 sal_Bool bInverseSemantics; // for booleanss: attribute and property value have the same or an inverse semantics? 256 257 AttributeAssignment() : pEnumMap(NULL), bInverseSemantics(sal_False) { } 258 }; 259 260 protected: 261 DECLARE_STL_USTRINGACCESS_MAP( AttributeAssignment, AttributeAssignments ); 262 AttributeAssignments m_aKnownProperties; 263 264 public: 265 OAttribute2Property(); 266 virtual ~OAttribute2Property(); 267 268 /** return the AttributeAssignment which corresponds to the given attribute 269 270 @param _rAttribName 271 the name of the attrribute 272 @return 273 a pointer to the <type>AttributeAssignment</type> structure as requested, NULL if the attribute 274 does not represent a property. 275 */ 276 const AttributeAssignment* getAttributeTranslation( 277 const ::rtl::OUString& _rAttribName); 278 279 /** add a attribute assignment referring to a string property to the map 280 @param _pAttributeName 281 the name of the attrribute 282 @param _rPropertyName 283 the name of the property assigned to the attribute 284 @param _pAttributeDefault 285 the default value for the attribute, if any. May be NULL, in this case the default is assumed to be 286 an empty string. 287 */ 288 void addStringProperty( 289 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 290 const sal_Char* _pAttributeDefault = NULL); 291 292 /** add a attribute assignment referring to a boolean property to the map 293 294 @param _pAttributeName 295 the name of the attrribute 296 @param _rPropertyName 297 the name of the property assigned to the attribute 298 @param _bAttributeDefault 299 the default value for the attribute. 300 @param _bInverseSemantics 301 if <TRUE/>, a attribute value of <TRUE/> means a property value of <FALSE/> and vice verse.<br/> 302 if <FALSE/>, the attribute value is used as property value directly 303 */ 304 void addBooleanProperty( 305 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 306 const sal_Bool _bAttributeDefault, const sal_Bool _bInverseSemantics = sal_False); 307 308 /** add a attribute assignment referring to an int16 property to the map 309 310 @param _pAttributeName 311 the name of the attrribute 312 @param _rPropertyName 313 the name of the property assigned to the attribute 314 @param _nAttributeDefault 315 the default value for the attribute. 316 */ 317 void addInt16Property( 318 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 319 const sal_Int16 _nAttributeDefault); 320 321 /** add a attribute assignment referring to an int32 property to the map 322 323 @param _pAttributeName 324 the name of the attrribute 325 @param _rPropertyName 326 the name of the property assigned to the attribute 327 @param _nAttributeDefault 328 the default value for the attribute. 329 */ 330 void addInt32Property( 331 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 332 const sal_Int32 _nAttributeDefault ); 333 334 /** add a attribute assignment referring to an enum property to the map 335 336 @param _pAttributeName 337 the name of the attrribute 338 @param _rPropertyName 339 the name of the property assigned to the attribute 340 @param _nAttributeDefault 341 the default value for the attribute, as (32bit) integer 342 @param _pValueMap 343 the map to translate strings into enum values 344 @param _pType 345 the type of the property. May be NULL, in this case 32bit integer is assumed. 346 */ 347 void addEnumProperty( 348 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 349 const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap, 350 const ::com::sun::star::uno::Type* _pType = NULL); 351 352 protected: 353 /// some common code for the various add*Property methods 354 AttributeAssignment& implAdd( 355 const sal_Char* _pAttributeName, const ::rtl::OUString& _rPropertyName, 356 const ::com::sun::star::uno::Type& _rType, const ::rtl::OUString& _rDefaultString); 357 }; 358 //......................................................................... 359 } // namespace xmloff 360 //......................................................................... 361 362 #endif // _XMLOFF_FORMATTRIBUTES_HXX_ 363 364