LCOV - code coverage report
Current view: top level - sw/inc - fmtmeta.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 13 100.0 %
Date: 2014-11-03 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>SwTxtMeta</dt><dd>the text hint</dd>
      43             :  *   <dt>SwFmtMeta</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 SwTxtMeta;
      78             : class SwXMeta;
      79             : class SwXMetaField;
      80             : namespace sw {
      81             :     class Meta;
      82             : }
      83             : 
      84             : class SwFmtMeta
      85             :     : public SfxPoolItem
      86             : {
      87             : private:
      88             :     friend class SwTxtMeta; ///< needs SetTxtAttr, DoCopy
      89             :     friend class ::sw::Meta; ///< needs m_pTxtAttr
      90             : 
      91             :     ::boost::shared_ptr< ::sw::Meta > m_pMeta;
      92             :     SwTxtMeta * m_pTxtAttr;
      93             : 
      94        2194 :     SwTxtMeta * GetTxtAttr() { return m_pTxtAttr; }
      95             :     void SetTxtAttr(SwTxtMeta * const i_pTxtAttr);
      96             : 
      97             :     /// this method <em>must</em> be called when the hint is actually copied
      98             :     void DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
      99             :         SwTxtNode & i_rTargetTxtNode);
     100             : 
     101             :     explicit SwFmtMeta( const sal_uInt16 i_nWhich );
     102             : 
     103             : public:
     104             :     /// takes ownership
     105             :     explicit SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
     106             :                         const sal_uInt16 i_nWhich );
     107             :     virtual ~SwFmtMeta();
     108             : 
     109             :     /// SfxPoolItem
     110             :     virtual bool             operator==( const SfxPoolItem & ) const SAL_OVERRIDE;
     111             :     virtual SfxPoolItem *    Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
     112             : 
     113             :     /// notify clients registered at m_pMeta that this meta is being (re-)moved
     114             :     void NotifyChangeTxtNode(SwTxtNode *const pTxtNode);
     115             :     static SwFmtMeta * CreatePoolDefault( const sal_uInt16 i_nWhich );
     116         462 :     ::sw::Meta * GetMeta() { return m_pMeta.get(); }
     117             : };
     118             : 
     119             : namespace sw {
     120             : 
     121             : class MetaFieldManager;
     122             : 
     123             : class Meta
     124             :     : public ::sfx2::Metadatable
     125             :     , public SwModify
     126             : {
     127             : protected:
     128             :     friend class ::SwFmtMeta; ///< SetFmtMeta, NotifyChangeTxtNode
     129             :     friend class ::SwXMeta;   ///< GetTxtNode, GetTxtAttr, Get/SetXMeta
     130             : 
     131             :     ::com::sun::star::uno::WeakReference<
     132             :         ::com::sun::star::rdf::XMetadatable> m_wXMeta;
     133             : 
     134             :     SwFmtMeta * m_pFmt;
     135             :     SwTxtNode * m_pTxtNode;
     136             : 
     137             :     SwTxtMeta * GetTxtAttr() const;
     138        4012 :     SwTxtNode * GetTxtNode() const { return m_pTxtNode;} ///< @return 0 if not in document (undo)
     139             : 
     140        2854 :     SwFmtMeta * GetFmtMeta() const { return m_pFmt; }
     141         388 :     void SetFmtMeta( SwFmtMeta * const i_pFmt ) { m_pFmt = i_pFmt; };
     142             : 
     143             :     void NotifyChangeTxtNodeImpl();
     144             :     void NotifyChangeTxtNode(SwTxtNode *const pTxtNode);
     145             : 
     146             :     ::com::sun::star::uno::WeakReference<
     147         482 :         ::com::sun::star::rdf::XMetadatable> const& GetXMeta() const
     148         482 :             { return m_wXMeta; }
     149         662 :     void SetXMeta(::com::sun::star::uno::Reference<
     150             :                     ::com::sun::star::rdf::XMetadatable> const& xMeta)
     151         662 :             { m_wXMeta = xMeta; }
     152             : 
     153             :     /// SwClient
     154             :     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
     155             : 
     156             : public:
     157             :     explicit Meta(SwFmtMeta * const i_pFmt = 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         104 : class MetaField
     170             :     : public Meta
     171             : {
     172             : private:
     173             :     friend class ::SwFmtMeta;
     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           6 :     bool IsFixedLanguage() const    { return m_bIsFixedLanguage; }
     183          10 :     void SetIsFixedLanguage(bool b) { m_bIsFixedLanguage = b; }
     184             : 
     185             :     explicit MetaField(SwFmtMeta * const i_pFmt = 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        5045 : 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             :                 SwFmtMeta * const i_pFmt = 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.10