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 #ifndef SW_UNOBOOKMARK_HXX 25 #define SW_UNOBOOKMARK_HXX 26 27 #include <com/sun/star/lang/XUnoTunnel.hpp> 28 #include <com/sun/star/lang/XServiceInfo.hpp> 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 #include <com/sun/star/container/XNamed.hpp> 31 #include <com/sun/star/text/XTextContent.hpp> 32 #include <com/sun/star/text/XFormField.hpp> 33 34 #include <cppuhelper/implbase5.hxx> 35 36 #include <sfx2/Metadatable.hxx> 37 38 #include <unobaseclass.hxx> 39 #include <IDocumentMarkAccess.hxx> 40 41 42 class SwDoc; 43 44 45 typedef ::cppu::ImplInheritanceHelper5 46 < ::sfx2::MetadatableMixin 47 , ::com::sun::star::lang::XUnoTunnel 48 , ::com::sun::star::lang::XServiceInfo 49 , ::com::sun::star::beans::XPropertySet 50 , ::com::sun::star::container::XNamed 51 , ::com::sun::star::text::XTextContent 52 > SwXBookmark_Base; 53 54 class SwXBookmark 55 : public SwXBookmark_Base 56 { 57 58 private: 59 60 class Impl; 61 ::sw::UnoImplPtr<Impl> m_pImpl; 62 63 protected: 64 65 void attachToRangeEx( 66 const ::com::sun::star::uno::Reference< 67 ::com::sun::star::text::XTextRange > & xTextRange, 68 IDocumentMarkAccess::MarkType eType); 69 virtual void attachToRange( 70 const ::com::sun::star::uno::Reference< 71 ::com::sun::star::text::XTextRange > & xTextRange); 72 73 const ::sw::mark::IMark* GetBookmark() const; 74 75 virtual ~SwXBookmark(); 76 77 /// @param pDoc and pMark != 0, but not & because of ImplInheritanceHelper 78 SwXBookmark(::sw::mark::IMark *const pMark, SwDoc *const pDoc); 79 80 void registerInMark( ::sw::mark::IMark *const pBkmk ); 81 82 public: 83 84 /// descriptor 85 SwXBookmark(); 86 87 static ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent > 88 CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark); 89 90 /// @return IMark for this, but only if it lives in pDoc 91 static ::sw::mark::IMark const* GetBookmarkInDoc(SwDoc const*const pDoc, 92 const ::com::sun::star::uno::Reference< 93 ::com::sun::star::lang::XUnoTunnel> & xUT); 94 95 // MetadatableMixin 96 virtual ::sfx2::Metadatable* GetCoreObject(); 97 virtual ::com::sun::star::uno::Reference< 98 ::com::sun::star::frame::XModel > GetModel(); 99 100 static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId(); 101 102 // XUnoTunnel 103 virtual sal_Int64 SAL_CALL getSomething( 104 const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier); 105 106 // XServiceInfo 107 virtual ::rtl::OUString SAL_CALL getImplementationName(); 108 virtual sal_Bool SAL_CALL supportsService( 109 const ::rtl::OUString& rServiceName); 110 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 111 getSupportedServiceNames(); 112 113 // XComponent 114 virtual void SAL_CALL dispose(); 115 virtual void SAL_CALL addEventListener( 116 const ::com::sun::star::uno::Reference< 117 ::com::sun::star::lang::XEventListener > & xListener); 118 virtual void SAL_CALL removeEventListener( 119 const ::com::sun::star::uno::Reference< 120 ::com::sun::star::lang::XEventListener > & xListener); 121 122 // XPropertySet 123 virtual ::com::sun::star::uno::Reference< 124 ::com::sun::star::beans::XPropertySetInfo > SAL_CALL 125 getPropertySetInfo(); 126 virtual void SAL_CALL setPropertyValue( 127 const ::rtl::OUString& rPropertyName, 128 const ::com::sun::star::uno::Any& rValue); 129 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( 130 const ::rtl::OUString& rPropertyName); 131 virtual void SAL_CALL addPropertyChangeListener( 132 const ::rtl::OUString& rPropertyName, 133 const ::com::sun::star::uno::Reference< 134 ::com::sun::star::beans::XPropertyChangeListener >& xListener); 135 virtual void SAL_CALL removePropertyChangeListener( 136 const ::rtl::OUString& rPropertyName, 137 const ::com::sun::star::uno::Reference< 138 ::com::sun::star::beans::XPropertyChangeListener >& xListener); 139 virtual void SAL_CALL addVetoableChangeListener( 140 const ::rtl::OUString& rPropertyName, 141 const ::com::sun::star::uno::Reference< 142 ::com::sun::star::beans::XVetoableChangeListener >& xListener); 143 virtual void SAL_CALL removeVetoableChangeListener( 144 const ::rtl::OUString& rPropertyName, 145 const ::com::sun::star::uno::Reference< 146 ::com::sun::star::beans::XVetoableChangeListener >& xListener); 147 148 // XNamed 149 virtual ::rtl::OUString SAL_CALL getName(); 150 virtual void SAL_CALL setName(const ::rtl::OUString& rName); 151 152 // XTextContent 153 virtual void SAL_CALL attach( 154 const ::com::sun::star::uno::Reference< 155 ::com::sun::star::text::XTextRange > & xTextRange); 156 virtual ::com::sun::star::uno::Reference< 157 ::com::sun::star::text::XTextRange > SAL_CALL getAnchor(); 158 159 }; 160 161 class SwXFieldmarkParameters 162 : public ::cppu::WeakImplHelper1< ::com::sun::star::container::XNameContainer> 163 , private SwClient 164 { 165 public: SwXFieldmarkParameters(::sw::mark::IFieldmark * const pFieldmark)166 SwXFieldmarkParameters(::sw::mark::IFieldmark* const pFieldmark) 167 { 168 pFieldmark->Add(this); 169 } 170 171 // XNameContainer 172 virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ); 173 virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ); 174 // XNameReplace 175 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ); 176 // XNameAccess 177 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 178 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ); 179 virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 180 // XElementAccess 181 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ); 182 virtual ::sal_Bool SAL_CALL hasElements( ); 183 protected: 184 //SwClient 185 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ); 186 private: 187 ::sw::mark::IFieldmark::parameter_map_t* getCoreParameters(); 188 }; 189 190 typedef cppu::ImplInheritanceHelper1< SwXBookmark, 191 ::com::sun::star::text::XFormField > SwXFieldmark_Base; 192 193 class SwXFieldmark 194 : public SwXFieldmark_Base 195 { 196 197 private: 198 199 bool isReplacementObject; 200 201 SwXFieldmark( 202 bool _isReplacementObject, 203 ::sw::mark::IMark *const pMark, 204 SwDoc *const pDoc ); 205 206 public: 207 208 // <SwXFieldmark> instance not attached to the document - property descriptor available 209 SwXFieldmark( bool isReplacementObject ); 210 211 // (as the parent class) newly created <SwXFieldmark> instances for an existing <IMark> instance needs to be registered in the Mark 212 static ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent > 213 CreateXFieldmark( 214 SwDoc & rDoc, 215 ::sw::mark::IMark & rBookmark ); 216 217 virtual void attachToRange( 218 const ::com::sun::star::uno::Reference< 219 ::com::sun::star::text::XTextRange > & xTextRange); 220 virtual ::rtl::OUString SAL_CALL getFieldType(void); 221 virtual void SAL_CALL setFieldType(const ::rtl::OUString& description ); 222 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL getParameters( ); 223 224 }; 225 226 #endif // SW_UNOBOOKMARK_HXX 227