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 SW_UNOMETA_HXX 29 #define SW_UNOMETA_HXX 30 31 #include <deque> 32 33 #include <com/sun/star/lang/XServiceInfo.hpp> 34 #include <com/sun/star/lang/XUnoTunnel.hpp> 35 #include <com/sun/star/beans/XPropertySet.hpp> 36 #include <com/sun/star/container/XChild.hpp> 37 #include <com/sun/star/container/XEnumerationAccess.hpp> 38 #include <com/sun/star/text/XTextContent.hpp> 39 #include <com/sun/star/text/XTextField.hpp> 40 41 #include <cppuhelper/implbase2.hxx> 42 #include <cppuhelper/implbase6.hxx> 43 44 #include <sfx2/Metadatable.hxx> 45 46 #include <unobaseclass.hxx> 47 48 49 typedef ::std::deque< 50 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > > 51 TextRangeList_t; 52 53 class SwPaM; 54 class SwTxtNode; 55 56 namespace sw { 57 class Meta; 58 class MetaField; 59 } 60 61 typedef ::cppu::ImplInheritanceHelper6 62 < ::sfx2::MetadatableMixin 63 , ::com::sun::star::lang::XUnoTunnel 64 , ::com::sun::star::lang::XServiceInfo 65 , ::com::sun::star::container::XChild 66 , ::com::sun::star::container::XEnumerationAccess 67 , ::com::sun::star::text::XTextContent 68 , ::com::sun::star::text::XText 69 > SwXMeta_Base; 70 71 class SwXMeta 72 : public SwXMeta_Base 73 , private ::boost::noncopyable 74 { 75 76 public: 77 78 class Impl; 79 80 protected: 81 82 ::sw::UnoImplPtr<Impl> m_pImpl; 83 84 virtual void SAL_CALL AttachImpl( 85 const ::com::sun::star::uno::Reference< 86 ::com::sun::star::text::XTextRange > & xTextRange, 87 const sal_uInt16 nWhich) 88 throw (::com::sun::star::lang::IllegalArgumentException, 89 ::com::sun::star::uno::RuntimeException); 90 91 virtual ~SwXMeta(); 92 93 /// @param pDoc and pMeta != 0, but not & because of ImplInheritanceHelper 94 SwXMeta(SwDoc *const pDoc, ::sw::Meta *const pMeta, 95 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const& 96 xParentText, 97 TextRangeList_t const*const pPortions); 98 99 public: 100 101 SwXMeta(SwDoc *const pDoc); 102 103 static ::com::sun::star::uno::Reference< 104 ::com::sun::star::rdf::XMetadatable > 105 CreateXMeta( 106 ::sw::Meta & rMeta, 107 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> 108 const& xParentText = 0, 109 ::std::auto_ptr<TextRangeList_t const> pPortions = 110 ::std::auto_ptr<TextRangeList_t const>(0)); 111 112 /// init params with position of the attribute content (w/out CH_TXTATR) 113 bool SetContentRange( 114 SwTxtNode *& rpNode, xub_StrLen & rStart, xub_StrLen & rEnd) const; 115 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > 116 GetParentText() const; 117 118 bool CheckForOwnMemberMeta(const SwPaM & rPam, const bool bAbsorb) 119 throw (::com::sun::star::lang::IllegalArgumentException, 120 ::com::sun::star::uno::RuntimeException); 121 122 // MetadatableMixin 123 virtual ::sfx2::Metadatable * GetCoreObject(); 124 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > 125 GetModel(); 126 127 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); 128 129 // XUnoTunnel 130 virtual sal_Int64 SAL_CALL getSomething( 131 const ::com::sun::star::uno::Sequence< sal_Int8 >& Identifier ) 132 throw (::com::sun::star::uno::RuntimeException); 133 134 // XServiceInfo 135 virtual ::rtl::OUString SAL_CALL getImplementationName() 136 throw (::com::sun::star::uno::RuntimeException); 137 virtual sal_Bool SAL_CALL supportsService( 138 const ::rtl::OUString& rServiceName) 139 throw (::com::sun::star::uno::RuntimeException); 140 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 141 getSupportedServiceNames() 142 throw (::com::sun::star::uno::RuntimeException); 143 144 // XComponent 145 virtual void SAL_CALL dispose() 146 throw (::com::sun::star::uno::RuntimeException); 147 virtual void SAL_CALL addEventListener( 148 const ::com::sun::star::uno::Reference< 149 ::com::sun::star::lang::XEventListener > & xListener) 150 throw (::com::sun::star::uno::RuntimeException); 151 virtual void SAL_CALL removeEventListener( 152 const ::com::sun::star::uno::Reference< 153 ::com::sun::star::lang::XEventListener > & xListener) 154 throw (::com::sun::star::uno::RuntimeException); 155 156 // XChild 157 virtual ::com::sun::star::uno::Reference< 158 ::com::sun::star::uno::XInterface > SAL_CALL 159 getParent() 160 throw (::com::sun::star::uno::RuntimeException); 161 virtual void SAL_CALL setParent( 162 ::com::sun::star::uno::Reference< 163 ::com::sun::star::uno::XInterface> const& xParent) 164 throw (::com::sun::star::uno::RuntimeException, 165 ::com::sun::star::lang::NoSupportException); 166 167 // XElementAccess 168 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() 169 throw (::com::sun::star::uno::RuntimeException); 170 virtual sal_Bool SAL_CALL hasElements() 171 throw (::com::sun::star::uno::RuntimeException); 172 173 // XEnumerationAccess 174 virtual ::com::sun::star::uno::Reference< 175 ::com::sun::star::container::XEnumeration > SAL_CALL 176 createEnumeration() 177 throw (::com::sun::star::uno::RuntimeException); 178 179 // XTextContent 180 virtual void SAL_CALL attach( 181 const ::com::sun::star::uno::Reference< 182 ::com::sun::star::text::XTextRange > & xTextRange) 183 throw (::com::sun::star::lang::IllegalArgumentException, 184 ::com::sun::star::uno::RuntimeException); 185 virtual ::com::sun::star::uno::Reference< 186 ::com::sun::star::text::XTextRange > SAL_CALL getAnchor() 187 throw (::com::sun::star::uno::RuntimeException); 188 189 // XTextRange 190 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > 191 SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException); 192 virtual ::com::sun::star::uno::Reference< 193 ::com::sun::star::text::XTextRange > SAL_CALL getStart() 194 throw (::com::sun::star::uno::RuntimeException); 195 virtual ::com::sun::star::uno::Reference< 196 ::com::sun::star::text::XTextRange > SAL_CALL getEnd() 197 throw (::com::sun::star::uno::RuntimeException); 198 virtual rtl::OUString SAL_CALL getString() 199 throw (::com::sun::star::uno::RuntimeException); 200 virtual void SAL_CALL setString(const rtl::OUString& rString) 201 throw (::com::sun::star::uno::RuntimeException); 202 203 // XSimpleText 204 virtual ::com::sun::star::uno::Reference< 205 ::com::sun::star::text::XTextCursor > SAL_CALL 206 createTextCursor() 207 throw (::com::sun::star::uno::RuntimeException); 208 virtual ::com::sun::star::uno::Reference< 209 ::com::sun::star::text::XTextCursor > SAL_CALL 210 createTextCursorByRange( 211 const ::com::sun::star::uno::Reference< 212 ::com::sun::star::text::XTextRange > & xTextPosition) 213 throw (::com::sun::star::uno::RuntimeException); 214 virtual void SAL_CALL insertString( 215 const ::com::sun::star::uno::Reference< 216 ::com::sun::star::text::XTextRange > & xRange, 217 const rtl::OUString& aString, sal_Bool bAbsorb) 218 throw (::com::sun::star::uno::RuntimeException); 219 virtual void SAL_CALL insertControlCharacter( 220 const ::com::sun::star::uno::Reference< 221 ::com::sun::star::text::XTextRange > & xRange, 222 sal_Int16 nControlCharacter, sal_Bool bAbsorb) 223 throw (::com::sun::star::lang::IllegalArgumentException, 224 ::com::sun::star::uno::RuntimeException); 225 226 // XText 227 virtual void SAL_CALL insertTextContent( 228 const ::com::sun::star::uno::Reference< 229 ::com::sun::star::text::XTextRange > & xRange, 230 const ::com::sun::star::uno::Reference< 231 ::com::sun::star::text::XTextContent > & xContent, 232 sal_Bool bAbsorb) 233 throw (::com::sun::star::lang::IllegalArgumentException, 234 ::com::sun::star::uno::RuntimeException); 235 virtual void SAL_CALL removeTextContent( 236 const ::com::sun::star::uno::Reference< 237 ::com::sun::star::text::XTextContent > & xContent) 238 throw (::com::sun::star::container::NoSuchElementException, 239 ::com::sun::star::uno::RuntimeException); 240 241 }; 242 243 244 typedef ::cppu::ImplInheritanceHelper2 245 < SwXMeta 246 , ::com::sun::star::beans::XPropertySet 247 , ::com::sun::star::text::XTextField 248 > SwXMetaField_Base; 249 250 class SwXMetaField 251 : public SwXMetaField_Base 252 { 253 254 private: 255 256 virtual ~SwXMetaField(); 257 258 friend ::com::sun::star::uno::Reference< 259 ::com::sun::star::rdf::XMetadatable > 260 SwXMeta::CreateXMeta(::sw::Meta &, 261 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> 262 const&, 263 ::std::auto_ptr<TextRangeList_t const> pPortions); 264 265 SwXMetaField(SwDoc *const pDoc, ::sw::Meta *const pMeta, 266 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText> const& 267 xParentText, 268 TextRangeList_t const*const pPortions); 269 270 public: 271 272 SwXMetaField(SwDoc *const pDoc); 273 274 // XServiceInfo 275 virtual ::rtl::OUString SAL_CALL getImplementationName() 276 throw (::com::sun::star::uno::RuntimeException); 277 virtual sal_Bool SAL_CALL supportsService( 278 const ::rtl::OUString& ServiceName) 279 throw (::com::sun::star::uno::RuntimeException); 280 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 281 getSupportedServiceNames( ) 282 throw (::com::sun::star::uno::RuntimeException); 283 284 // XComponent 285 virtual void SAL_CALL dispose() 286 throw (::com::sun::star::uno::RuntimeException); 287 virtual void SAL_CALL addEventListener( 288 const ::com::sun::star::uno::Reference< 289 ::com::sun::star::lang::XEventListener > & xListener) 290 throw (::com::sun::star::uno::RuntimeException); 291 virtual void SAL_CALL removeEventListener( 292 const ::com::sun::star::uno::Reference< 293 ::com::sun::star::lang::XEventListener > & xListener) 294 throw (::com::sun::star::uno::RuntimeException); 295 296 // XPropertySet 297 virtual ::com::sun::star::uno::Reference< 298 ::com::sun::star::beans::XPropertySetInfo > SAL_CALL 299 getPropertySetInfo() 300 throw (::com::sun::star::uno::RuntimeException); 301 virtual void SAL_CALL setPropertyValue( 302 const ::rtl::OUString& rPropertyName, 303 const ::com::sun::star::uno::Any& rValue) 304 throw (::com::sun::star::beans::UnknownPropertyException, 305 ::com::sun::star::beans::PropertyVetoException, 306 ::com::sun::star::lang::IllegalArgumentException, 307 ::com::sun::star::lang::WrappedTargetException, 308 ::com::sun::star::uno::RuntimeException); 309 virtual ::com::sun::star::uno::Any SAL_CALL 310 getPropertyValue(const ::rtl::OUString& rPropertyName) 311 throw (::com::sun::star::beans::UnknownPropertyException, 312 ::com::sun::star::lang::WrappedTargetException, 313 ::com::sun::star::uno::RuntimeException); 314 virtual void SAL_CALL addPropertyChangeListener( 315 const ::rtl::OUString& rPropertyName, 316 const ::com::sun::star::uno::Reference< 317 ::com::sun::star::beans::XPropertyChangeListener >& xListener) 318 throw (::com::sun::star::beans::UnknownPropertyException, 319 ::com::sun::star::lang::WrappedTargetException, 320 ::com::sun::star::uno::RuntimeException); 321 virtual void SAL_CALL removePropertyChangeListener( 322 const ::rtl::OUString& rPropertyName, 323 const ::com::sun::star::uno::Reference< 324 ::com::sun::star::beans::XPropertyChangeListener >& xListener) 325 throw (::com::sun::star::beans::UnknownPropertyException, 326 ::com::sun::star::lang::WrappedTargetException, 327 ::com::sun::star::uno::RuntimeException); 328 virtual void SAL_CALL addVetoableChangeListener( 329 const ::rtl::OUString& rPropertyName, 330 const ::com::sun::star::uno::Reference< 331 ::com::sun::star::beans::XVetoableChangeListener >& xListener) 332 throw (::com::sun::star::beans::UnknownPropertyException, 333 ::com::sun::star::lang::WrappedTargetException, 334 ::com::sun::star::uno::RuntimeException); 335 virtual void SAL_CALL removeVetoableChangeListener( 336 const ::rtl::OUString& rPropertyName, 337 const ::com::sun::star::uno::Reference< 338 ::com::sun::star::beans::XVetoableChangeListener >& xListener) 339 throw (::com::sun::star::beans::UnknownPropertyException, 340 ::com::sun::star::lang::WrappedTargetException, 341 ::com::sun::star::uno::RuntimeException); 342 343 // XTextContent 344 virtual void SAL_CALL attach( 345 const ::com::sun::star::uno::Reference< 346 ::com::sun::star::text::XTextRange > & xTextRange) 347 throw ( ::com::sun::star::lang::IllegalArgumentException, 348 ::com::sun::star::uno::RuntimeException ); 349 virtual ::com::sun::star::uno::Reference< 350 ::com::sun::star::text::XTextRange > SAL_CALL getAnchor() 351 throw (::com::sun::star::uno::RuntimeException); 352 353 // XTextField 354 virtual rtl::OUString SAL_CALL getPresentation(sal_Bool bShowCommand) 355 throw (::com::sun::star::uno::RuntimeException); 356 357 }; 358 359 /// get prefix/suffix from the RDF repository. @throws RuntimeException 360 void getPrefixAndSuffix( 361 const ::com::sun::star::uno::Reference< 362 ::com::sun::star::frame::XModel>& xModel, 363 const ::com::sun::star::uno::Reference< 364 ::com::sun::star::rdf::XMetadatable>& xMetaField, 365 ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix); 366 367 #endif // SW_UNOMETA_HXX 368 369