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 #ifndef _UNOFIELD_HXX 24 #define _UNOFIELD_HXX 25 26 #include <com/sun/star/lang/XUnoTunnel.hpp> 27 #include <com/sun/star/util/XRefreshable.hpp> 28 #include <com/sun/star/util/XUpdatable.hpp> 29 #include <com/sun/star/text/XDependentTextField.hpp> 30 31 #include <cppuhelper/implbase5.hxx> 32 33 #include <calbck.hxx> 34 #include <unocoll.hxx> 35 #include <RefreshListenerContainer.hxx> 36 37 38 class SwFieldType; 39 class SwDoc; 40 class SwFmtFld; 41 class SwField; 42 class SwSetExpField; 43 class SwTextAPIObject; 44 45 /* -----------------04.12.98 12:49------------------- 46 * 47 * --------------------------------------------------*/ 48 class SwXFieldMaster : public cppu::WeakImplHelper4 49 < 50 ::com::sun::star::beans::XPropertySet, 51 ::com::sun::star::lang::XServiceInfo, 52 ::com::sun::star::lang::XUnoTunnel, 53 ::com::sun::star::lang::XComponent 54 >, 55 public SwClient 56 { 57 SwEventListenerContainer aLstnrCntnr; 58 sal_uInt16 nResTypeId; 59 SwDoc* m_pDoc; 60 61 sal_Bool m_bIsDescriptor; 62 63 String sParam1; //Content / Database / NumberingSeparator 64 String sParam2; // - /DataTablename 65 String sParam3; // - /DataFieldName 66 String sParam4; 67 String sParam5; // - /DataBaseURL 68 String sParam6; // - /DataBaseResource 69 double fParam1; // Value / - 70 sal_Int8 nParam1; // ChapterNumberingLevel 71 sal_Bool bParam1; // IsExpression 72 sal_Int32 nParam2; 73 74 protected: 75 virtual ~SwXFieldMaster(); 76 //SwClient 77 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); 78 79 public: 80 81 SwXFieldMaster(SwDoc* pDoc, sal_uInt16 nResId); 82 SwXFieldMaster(SwFieldType& rType, SwDoc* pDoc); 83 84 85 TYPEINFO(); 86 87 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); 88 89 //XUnoTunnel 90 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); 91 92 //XPropertySet 93 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 94 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 95 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 96 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 97 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 98 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 99 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 100 101 //XComponent 102 virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException ); 103 virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ); 104 virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ); 105 106 //XServiceInfo 107 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException ); 108 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); 109 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); 110 111 static rtl::OUString GetProgrammaticName(const SwFieldType& rType, SwDoc& rDoc); 112 static rtl::OUString LocalizeFormula(const SwSetExpField& rFld, const rtl::OUString& rFormula, sal_Bool bQuery); 113 114 SwFieldType* GetFldType(sal_Bool bDontCreate = sal_False) const; GetDoc()115 SwDoc* GetDoc() {return m_pDoc;} 116 IsDescriptor() const117 sal_Bool IsDescriptor()const {return m_bIsDescriptor;} GetResId() const118 sal_uInt16 GetResId() const {return nResTypeId;} 119 }; 120 121 struct SwFieldProperties_Impl; 122 class SwXTextField : public cppu::WeakImplHelper5 123 < 124 ::com::sun::star::text::XDependentTextField, 125 ::com::sun::star::lang::XServiceInfo, 126 ::com::sun::star::beans::XPropertySet, 127 ::com::sun::star::lang::XUnoTunnel, 128 ::com::sun::star::util::XUpdatable 129 >, 130 public SwClient 131 { 132 SwEventListenerContainer m_aLstnrCntnr; 133 const SwFmtFld* m_pFmtFld; 134 SwDoc* m_pDoc; 135 SwTextAPIObject* m_pTextObject; 136 137 sal_Bool m_bIsDescriptor; 138 SwClient m_aFieldTypeClient; // required to access field master of not yet inserted fields 139 sal_Bool m_bCallUpdate; 140 sal_uInt16 m_nServiceId; 141 SwFieldProperties_Impl* m_pProps; 142 String m_sTypeName; 143 144 145 //SwFieldType* GetFldType() const { return (SwFieldType*)GetRegisteredIn(); } GetDoc()146 SwDoc* GetDoc() {return m_pDoc;} 147 protected: 148 virtual ~SwXTextField(); 149 //SwClient 150 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); 151 152 public: 153 SwXTextField(sal_uInt16 nServiceId, SwDoc* pDoc=0); 154 SwXTextField(const SwFmtFld& rFmt, SwDoc* pDoc); 155 156 157 TYPEINFO(); 158 159 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId(); 160 161 //XUnoTunnel 162 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); 163 164 //XDependentTextField 165 virtual void SAL_CALL attachTextFieldMaster(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xFieldMaster) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); 166 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL getTextFieldMaster(void) throw( ::com::sun::star::uno::RuntimeException ); 167 168 //XTextField 169 virtual rtl::OUString SAL_CALL getPresentation(sal_Bool bShowCommand) throw( ::com::sun::star::uno::RuntimeException ); 170 171 //XTextContent 172 virtual void SAL_CALL attach(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange) throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); 173 virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL getAnchor(void) throw( ::com::sun::star::uno::RuntimeException ); 174 175 //XComponent 176 virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException ); 177 virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ); 178 virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & aListener) throw( ::com::sun::star::uno::RuntimeException ); 179 180 //XPropertySet 181 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 182 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 183 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 184 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 185 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 186 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 187 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 188 189 //XServiceInfo 190 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException ); 191 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); 192 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); 193 194 //XUpdatable 195 virtual void SAL_CALL update( ) throw (::com::sun::star::uno::RuntimeException); 196 197 void attachToRange(const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > & xTextRange)throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); 198 199 const SwField* GetField() const; GetFldFmt()200 const SwFmtFld* GetFldFmt(){return GetField() ? m_pFmtFld : 0; }; 201 202 void Invalidate(); 203 204 /// @return an SwXTextField, either an already existing one or a new one 205 static SwXTextField* CreateSwXTextField(SwDoc & rDoc, SwFmtFld const& rFmt); 206 sal_uInt16 GetServiceId(); 207 }; 208 209 210 typedef 211 cppu::WeakImplHelper2 212 < 213 ::com::sun::star::container::XNameAccess, 214 ::com::sun::star::lang::XServiceInfo 215 > 216 SwXTextFieldMastersBaseClass; 217 class SwXTextFieldMasters : public SwXTextFieldMastersBaseClass, 218 public SwUnoCollection 219 { 220 protected: 221 virtual ~SwXTextFieldMasters(); 222 public: 223 SwXTextFieldMasters(SwDoc* pDoc); 224 225 226 //XNameAccess 227 virtual ::com::sun::star::uno::Any SAL_CALL getByName(const rtl::OUString& Name) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); 228 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw( ::com::sun::star::uno::RuntimeException ); 229 virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& Name) throw( ::com::sun::star::uno::RuntimeException ); 230 231 //XElementAccess 232 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); 233 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); 234 235 //XServiceInfo 236 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException ); 237 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); 238 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); 239 240 241 static sal_Bool getInstanceName(const SwFieldType& rFldType, String& rName); 242 }; 243 244 /* -----------------21.12.98 10:26------------------- 245 * 246 * --------------------------------------------------*/ 247 typedef 248 cppu::WeakImplHelper3 249 < 250 ::com::sun::star::container::XEnumerationAccess, 251 ::com::sun::star::lang::XServiceInfo, 252 ::com::sun::star::util::XRefreshable 253 > 254 SwXTextFieldTypesBaseClass; 255 class SwXTextFieldTypes : public SwXTextFieldTypesBaseClass, 256 public SwUnoCollection 257 { 258 SwRefreshListenerContainer aRefreshCont; 259 protected: 260 virtual ~SwXTextFieldTypes(); 261 public: 262 SwXTextFieldTypes(SwDoc* pDoc); 263 264 265 //XEnumerationAccess 266 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(void) throw( ::com::sun::star::uno::RuntimeException ); 267 268 //XElementAccess 269 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); 270 virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); 271 272 // ::com::sun::star::util::XRefreshable 273 virtual void SAL_CALL refresh( ) throw(::com::sun::star::uno::RuntimeException); 274 virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException); 275 virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener >& l ) throw(::com::sun::star::uno::RuntimeException); 276 277 //XServiceInfo 278 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException ); 279 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); 280 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); 281 282 // SwUnoCollection 283 virtual void Invalidate(); 284 }; 285 286 class SwXFieldEnumeration : public cppu::WeakImplHelper2 287 < 288 ::com::sun::star::container::XEnumeration, 289 ::com::sun::star::lang::XServiceInfo 290 >, 291 public SwClient 292 { 293 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > > aItems; 294 sal_Int32 nNextIndex; // index of next element to be returned 295 296 SwDoc* pDoc; 297 298 protected: 299 virtual ~SwXFieldEnumeration(); 300 //SwClient 301 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); 302 public: 303 SwXFieldEnumeration(SwDoc* pDoc); 304 305 //XEnumeration 306 virtual sal_Bool SAL_CALL hasMoreElements(void) throw( ::com::sun::star::uno::RuntimeException ); 307 virtual ::com::sun::star::uno::Any SAL_CALL nextElement(void) throw( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); 308 309 //XServiceInfo 310 virtual rtl::OUString SAL_CALL getImplementationName(void) throw( ::com::sun::star::uno::RuntimeException ); 311 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException ); 312 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException ); 313 314 }; 315 #endif 316 317 318 319