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 #include "common.hxx" 29 #include "misc.hxx" 30 #include <xmlscript/xmldlg_imexp.hxx> 31 #include <xmlscript/xml_helper.hxx> 32 #include <osl/diagnose.h> 33 #include <com/sun/star/xml/sax/XAttributeList.hpp> 34 #include <com/sun/star/beans/XPropertySet.hpp> 35 #include <com/sun/star/beans/XPropertyState.hpp> 36 #include <com/sun/star/awt/FontDescriptor.hpp> 37 #include <com/sun/star/awt/FontEmphasisMark.hpp> 38 #include <com/sun/star/awt/FontRelief.hpp> 39 #include <vector> 40 41 42 namespace css = ::com::sun::star; 43 44 namespace xmlscript 45 { 46 47 struct Style 48 { 49 sal_uInt32 _backgroundColor; 50 sal_uInt32 _textColor; 51 sal_uInt32 _textLineColor; 52 sal_Int16 _border; 53 sal_Int32 _borderColor; 54 css::awt::FontDescriptor _descr; 55 sal_uInt16 _fontRelief; 56 sal_uInt16 _fontEmphasisMark; 57 sal_uInt32 _fillColor; 58 sal_Int16 _visualEffect; 59 60 // current highest mask: 0x40 61 short _all; 62 short _set; 63 64 ::rtl::OUString _id; 65 66 inline Style( short all_ ) SAL_THROW( () ) 67 : _fontRelief( css::awt::FontRelief::NONE ) 68 , _fontEmphasisMark( css::awt::FontEmphasisMark::NONE ) 69 , _all( all_ ) 70 , _set( 0 ) 71 {} 72 73 css::uno::Reference< css::xml::sax::XAttributeList > createElement(); 74 }; 75 class StyleBag 76 { 77 ::std::vector< Style * > _styles; 78 79 public: 80 ~StyleBag() SAL_THROW( () ); 81 82 ::rtl::OUString getStyleId( Style const & rStyle ) SAL_THROW( () ); 83 84 void dump( css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > 85 const & xOut ); 86 }; 87 88 class ElementDescriptor 89 : public ::xmlscript::XMLElement 90 { 91 css::uno::Reference< css::beans::XPropertySet > _xProps; 92 css::uno::Reference< css::beans::XPropertyState > _xPropState; 93 94 public: 95 inline ElementDescriptor( 96 css::uno::Reference< css::beans::XPropertySet > const & xProps, 97 css::uno::Reference< css::beans::XPropertyState > const & xPropState, 98 ::rtl::OUString const & name ) 99 SAL_THROW( () ) 100 : XMLElement( name ) 101 , _xProps( xProps ) 102 , _xPropState( xPropState ) 103 {} 104 inline ElementDescriptor( 105 ::rtl::OUString const & name ) 106 SAL_THROW( () ) 107 : XMLElement( name ) 108 {} 109 110 template<typename T> 111 inline void read( 112 ::rtl::OUString const & propName, ::rtl::OUString const & attrName, 113 bool forceAttribute = false ); 114 115 // 116 template<typename T> 117 inline bool readProp( T * ret, ::rtl::OUString const & rPropName ); 118 css::uno::Any readProp( ::rtl::OUString const & rPropName ); 119 // 120 void readDefaults( bool supportPrintable = true, bool supportVisible = true ); 121 // 122 void readStringAttr( 123 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 124 inline void readDoubleAttr( 125 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ) 126 { read<double>( rPropName, rAttrName ); } 127 inline void readLongAttr( 128 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName, 129 bool forceAttribute = false ) 130 { read<sal_Int32>( rPropName, rAttrName, forceAttribute ); } 131 void readHexLongAttr( 132 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 133 inline void readShortAttr( 134 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ) 135 { read<sal_Int32>( rPropName, rAttrName ); } 136 inline void readBoolAttr( 137 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ) 138 { read<sal_Bool>( rPropName, rAttrName ); } 139 140 void readAlignAttr( 141 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 142 void readVerticalAlignAttr( 143 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 144 void readImageAlignAttr( 145 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 146 void readImagePositionAttr( 147 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 148 void readDateFormatAttr( 149 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 150 void readTimeFormatAttr( 151 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 152 void readOrientationAttr( 153 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 154 void readButtonTypeAttr( 155 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 156 void readLineEndFormatAttr( 157 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 158 void readSelectionTypeAttr( 159 ::rtl::OUString const & rPropName, ::rtl::OUString const & rAttrName ); 160 // 161 inline void addBoolAttr( 162 ::rtl::OUString const & rAttrName, sal_Bool bValue ) 163 { addAttribute( rAttrName, ::rtl::OUString::valueOf(bValue) ); } 164 void addNumberFormatAttr( 165 css::uno::Reference< css::beans::XPropertySet > 166 const & xFormatProperties, 167 ::rtl::OUString const & rAttrName ); 168 169 // 170 void readEvents() SAL_THROW( (css::uno::Exception) ); 171 // 172 void readDialogModel( StyleBag * all_styles ) 173 SAL_THROW( (css::uno::Exception) ); 174 void readButtonModel( StyleBag * all_styles ) 175 SAL_THROW( (css::uno::Exception) ); 176 void readEditModel( StyleBag * all_styles ) 177 SAL_THROW( (css::uno::Exception) ); 178 void readCheckBoxModel( StyleBag * all_styles ) 179 SAL_THROW( (css::uno::Exception) ); 180 void readRadioButtonModel( StyleBag * all_styles ) 181 SAL_THROW( (css::uno::Exception) ); 182 void readComboBoxModel( StyleBag * all_styles ) 183 SAL_THROW( (css::uno::Exception) ); 184 void readCurrencyFieldModel( StyleBag * all_styles ) 185 SAL_THROW( (css::uno::Exception) ); 186 void readDateFieldModel( StyleBag * all_styles ) 187 SAL_THROW( (css::uno::Exception) ); 188 void readFileControlModel( StyleBag * all_styles ) 189 SAL_THROW( (css::uno::Exception) ); 190 void readTreeControlModel( StyleBag * all_styles ) 191 SAL_THROW( (css::uno::Exception) ); 192 void readFixedTextModel( StyleBag * all_styles ) 193 SAL_THROW( (css::uno::Exception) ); 194 void readGroupBoxModel( StyleBag * all_styles ) 195 SAL_THROW( (css::uno::Exception) ); 196 void readImageControlModel( StyleBag * all_styles ) 197 SAL_THROW( (css::uno::Exception) ); 198 void readListBoxModel( StyleBag * all_styles ) 199 SAL_THROW( (css::uno::Exception) ); 200 void readNumericFieldModel( StyleBag * all_styles ) 201 SAL_THROW( (css::uno::Exception) ); 202 void readPatternFieldModel( StyleBag * all_styles ) 203 SAL_THROW( (css::uno::Exception) ); 204 void readFormattedFieldModel( StyleBag * all_styles ) 205 SAL_THROW( (css::uno::Exception) ); 206 void readTimeFieldModel( StyleBag * all_styles ) 207 SAL_THROW( (css::uno::Exception) ); 208 void readFixedLineModel( StyleBag * all_styles ) 209 SAL_THROW( (css::uno::Exception) ); 210 void readProgressBarModel( StyleBag * all_styles ) 211 SAL_THROW( (css::uno::Exception) ); 212 void readScrollBarModel( StyleBag * all_styles ) 213 SAL_THROW( (css::uno::Exception) ); 214 void readFixedHyperLinkModel( StyleBag * all_styles ) 215 SAL_THROW( (css::uno::Exception) ); 216 }; 217 218 template<typename T> 219 inline void ElementDescriptor::read( 220 ::rtl::OUString const & propName, ::rtl::OUString const & attrName, 221 bool forceAttribute ) 222 { 223 if (forceAttribute || 224 css::beans::PropertyState_DEFAULT_VALUE != 225 _xPropState->getPropertyState( propName )) 226 { 227 css::uno::Any a( _xProps->getPropertyValue( propName ) ); 228 T v = T(); 229 if (a >>= v) 230 addAttribute( attrName, ::rtl::OUString::valueOf(v) ); 231 else 232 OSL_ENSURE( 0, "### unexpected property type!" ); 233 } 234 } 235 236 template<typename T> 237 inline bool ElementDescriptor::readProp( 238 T * ret, ::rtl::OUString const & rPropName ) 239 { 240 _xProps->getPropertyValue( rPropName ) >>= *ret; 241 return css::beans::PropertyState_DEFAULT_VALUE != 242 _xPropState->getPropertyState( rPropName ); 243 } 244 245 } 246