LCOV - code coverage report
Current view: top level - sw/inc - fmtmeta.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 13 100.0 %
Date: 2015-06-13 12:38:46 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_INC_FMTMETA_HXX
      21             : #define INCLUDED_SW_INC_FMTMETA_HXX
      22             : 
      23             : #include <cppuhelper/weakref.hxx>
      24             : 
      25             : #include <svl/poolitem.hxx>
      26             : #include <sfx2/Metadatable.hxx>
      27             : 
      28             : #include <boost/shared_ptr.hpp>
      29             : #include <boost/weak_ptr.hpp>
      30             : 
      31             : #include <vector>
      32             : 
      33             : namespace com { namespace sun { namespace star {
      34             :     namespace text {
      35             :         class XTextField;
      36             :     }
      37             : }}}
      38             : 
      39             : /**
      40             :  * The classes that make up a meta entity are:
      41             :  * <dl>
      42             :  *   <dt>SwTextMeta</dt><dd>the text hint</dd>
      43             :  *   <dt>SwFormatMeta</dt><dd>the pool item</dd>
      44             :  *   <dt>sw::Meta</dt><dd>the metadatable entity itself</dd>
      45             :  *   <dt>SwXMeta</dt><dd>the UNO wrapper object</dd>
      46             :  * </dl>
      47             :  *
      48             :  * The text hint contains the pool item (as usual) and has a pointer to the
      49             :  * text node at which it is attached.
      50             :  * The pool item has a shared pointer to the metadatable entity, and a reverse
      51             :  * pointer to the text attribute at which it is attached.
      52             :  * The pool item is non-poolable; it may only be attached to one text
      53             :  * attribute.
      54             :  * Of all the pool items that refer to a metadatable entity, only one may be
      55             :  * in the document content at any time. Others may be in the undo array, or in
      56             :  * undo objects.
      57             :  * The metadatable entity has a reverse pointer to the pool item that is
      58             :  * currently in the document. It also registers as a client at the text node
      59             :  * at which it is attached via this pool item and its text attribute.
      60             :  * The UNO wrapper object registers as a client at the metadatable entity.
      61             :  *
      62             :  * Copying the metadatable entity proceeds in the following way:
      63             :  * <ol>
      64             :  *   <li>The pool item is cloned (because it is non-poolable); the clone
      65             :  *       points to the same metadatable entity, but the metadatable entity's
      66             :  *       reverse pointer is unchanged.</li>
      67             :  *   <li>The DoCopy() method is called at the new pool item:
      68             :  *       it will clone the metadatable entity (using RegisterAsCopyOf).
      69             :  *       This is necessary, because first, a metadatable entity may
      70             :  *       only be inserted once into a document, and second, the copy may be
      71             :  *       inserted into a different document than the source document!</li>
      72             :  *   <li>A new text hint is created, taking over the new pool item.</li>
      73             :  *   <li>The text hint is inserted into the hints array of some text node.</li>
      74             :  * </ol>
      75             :  */
      76             : 
      77             : class SwTextMeta;
      78             : class SwXMeta;
      79             : class SwXMetaField;
      80             : class SwTextNode;
      81             : namespace sw {
      82             :     class Meta;
      83             :     class MetaFieldManager;
      84             : }
      85             : 
      86             : class SwFormatMeta
      87             :     : public SfxPoolItem
      88             : {
      89             : private:
      90             :     friend class SwTextMeta; ///< needs SetTextAttr, DoCopy
      91             :     friend class ::sw::Meta; ///< needs m_pTextAttr
      92             : 
      93             :     ::boost::shared_ptr< ::sw::Meta > m_pMeta;
      94             :     SwTextMeta * m_pTextAttr;
      95             : 
      96        1133 :     SwTextMeta * GetTextAttr() { return m_pTextAttr; }
      97             :     void SetTextAttr(SwTextMeta * const i_pTextAttr);
      98             : 
      99             :     /// this method <em>must</em> be called when the hint is actually copied
     100             :     void DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
     101             :         SwTextNode & i_rTargetTextNode);
     102             : 
     103             :     explicit SwFormatMeta( const sal_uInt16 i_nWhich );
     104             : 
     105             : public:
     106             :     /// takes ownership
     107             :     explicit SwFormatMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
     108             :                         const sal_uInt16 i_nWhich );
     109             :     virtual ~SwFormatMeta();
     110             : 
     111             :     /// SfxPoolItem
     112             :     virtual bool             operator==( const SfxPoolItem & ) const SAL_OVERRIDE;
     113             :     virtual SfxPoolItem *    Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
     114             : 
     115             :     /// notify clients registered at m_pMeta that this meta is being (re-)moved
     116             :     void NotifyChangeTextNode(SwTextNode *const pTextNode);
     117             :     static SwFormatMeta * CreatePoolDefault( const sal_uInt16 i_nWhich );
     118         251 :     ::sw::Meta * GetMeta() { return m_pMeta.get(); }
     119             : };
     120             : 
     121             : namespace sw {
     122             : 
     123             : class Meta
     124             :     : public ::sfx2::Metadatable
     125             :     , public SwModify
     126             : {
     127             : protected:
     128             :     friend class ::SwFormatMeta; ///< SetFormatMeta, NotifyChangeTextNode
     129             :     friend class ::SwXMeta;   ///< GetTextNode, GetTextAttr, Get/SetXMeta
     130             : 
     131             :     ::com::sun::star::uno::WeakReference<
     132             :         ::com::sun::star::rdf::XMetadatable> m_wXMeta;
     133             : 
     134             :     SwFormatMeta * m_pFormat;
     135             :     SwTextNode * m_pTextNode;
     136             : 
     137             :     SwTextMeta * GetTextAttr() const;
     138        2162 :     SwTextNode * GetTextNode() const { return m_pTextNode;} ///< @return 0 if not in document (undo)
     139             : 
     140        1463 :     SwFormatMeta * GetFormatMeta() const { return m_pFormat; }
     141         194 :     void SetFormatMeta( SwFormatMeta * const i_pFormat ) { m_pFormat = i_pFormat; };
     142             : 
     143             :     void NotifyChangeTextNodeImpl();
     144             :     void NotifyChangeTextNode(SwTextNode *const pTextNode);
     145             : 
     146             :     ::com::sun::star::uno::WeakReference<
     147         261 :         ::com::sun::star::rdf::XMetadatable> const& GetXMeta() const
     148         261 :             { return m_wXMeta; }
     149         367 :     void SetXMeta(::com::sun::star::uno::Reference<
     150             :                     ::com::sun::star::rdf::XMetadatable> const& xMeta)
     151         367 :             { m_wXMeta = xMeta; }
     152             : 
     153             :     /// SwClient
     154             :     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
     155             : 
     156             : public:
     157             :     explicit Meta(SwFormatMeta * const i_pFormat = 0);
     158             :     virtual ~Meta();
     159             : 
     160             :     /// sfx2::Metadatable
     161             :     virtual ::sfx2::IXmlIdRegistry& GetRegistry() SAL_OVERRIDE;
     162             :     virtual bool IsInClipboard() const SAL_OVERRIDE;
     163             :     virtual bool IsInUndo() const SAL_OVERRIDE;
     164             :     virtual bool IsInContent() const SAL_OVERRIDE;
     165             :     virtual ::com::sun::star::uno::Reference<
     166             :         ::com::sun::star::rdf::XMetadatable > MakeUnoObject() SAL_OVERRIDE;
     167             : };
     168             : 
     169          52 : class MetaField
     170             :     : public Meta
     171             : {
     172             : private:
     173             :     friend class ::SwFormatMeta;
     174             :     friend class ::SwXMetaField;
     175             :     friend class ::sw::MetaFieldManager;
     176             : 
     177             :     sal_uInt32 m_nNumberFormat;
     178             :     bool       m_bIsFixedLanguage;
     179             : 
     180             :     sal_uInt32 GetNumberFormat(OUString const & rContent) const;
     181             :     void SetNumberFormat(sal_uInt32 nNumberFormat);
     182           3 :     bool IsFixedLanguage() const    { return m_bIsFixedLanguage; }
     183           5 :     void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
     184             : 
     185             :     explicit MetaField(SwFormatMeta * const i_pFormat = 0,
     186             :             const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
     187             :             const bool bIsFixedLanguage = false );
     188             : 
     189             : public:
     190             :     /// get prefix/suffix from the RDF repository. @throws RuntimeException
     191             :     void GetPrefixAndSuffix(
     192             :         OUString *const o_pPrefix, OUString *const o_pSuffix);
     193             : };
     194             : 
     195             :     /// knows all meta-fields in the document.
     196        2949 : class MetaFieldManager
     197             :     : private ::boost::noncopyable
     198             : {
     199             : private:
     200             :     typedef ::std::vector< ::boost::weak_ptr<MetaField> > MetaFieldList_t;
     201             :     MetaFieldList_t m_MetaFields;
     202             : 
     203             : public:
     204             :     MetaFieldManager();
     205             :     ::boost::shared_ptr<MetaField> makeMetaField(
     206             :                 SwFormatMeta * const i_pFormat = 0,
     207             :                 const sal_uInt32 nNumberFormat = SAL_MAX_UINT32,
     208             :                 const bool bIsFixedLanguage = false );
     209             :     /// get all meta fields
     210             :     ::std::vector< ::com::sun::star::uno::Reference<
     211             :         ::com::sun::star::text::XTextField> > getMetaFields();
     212             : };
     213             : 
     214             : } // namespace sw
     215             : 
     216             : #endif // INCLUDED_SW_INC_FMTMETA_HXX
     217             : 
     218             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11