LCOV - code coverage report
Current view: top level - sw/inc - expfld.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 45 67 67.2 %
Date: 2015-06-13 12:38:46 Functions: 36 52 69.2 %
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             : #ifndef INCLUDED_SW_INC_EXPFLD_HXX
      20             : #define INCLUDED_SW_INC_EXPFLD_HXX
      21             : 
      22             : #include "swdllapi.h"
      23             : #include <fldbas.hxx>
      24             : #include <cellfml.hxx>
      25             : #include <set>
      26             : #include <vector>
      27             : 
      28             : class SfxPoolItem;
      29             : class SwTextNode;
      30             : class SwFrm;
      31             : struct SwPosition;
      32             : class SwTextField;
      33             : class SwDoc;
      34             : class SwFormatField;
      35             : class _SetGetExpFields;
      36             : class SwEditShell;
      37             : 
      38             : /// Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
      39             : const SwTextNode* GetBodyTextNode( const SwDoc& pDoc, SwPosition& rPos,
      40             :                                  const SwFrm& rFrm );
      41             : 
      42             : OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false);
      43             : 
      44           0 : struct _SeqFieldLstElem
      45             : {
      46             :     OUString sDlgEntry;
      47             :     sal_uInt16 nSeqNo;
      48             : 
      49           0 :     _SeqFieldLstElem( const OUString& rStr, sal_uInt16 nNo )
      50           0 :         : sDlgEntry( rStr ), nSeqNo( nNo )
      51           0 :     {}
      52             : };
      53             : 
      54           0 : class SW_DLLPUBLIC SwSeqFieldList
      55             : {
      56             :     std::vector<_SeqFieldLstElem*> maData;
      57             : public:
      58           0 :     ~SwSeqFieldList()
      59           0 :     {
      60           0 :         for( std::vector<_SeqFieldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it )
      61           0 :             delete *it;
      62           0 :     }
      63             : 
      64             :     bool InsertSort(_SeqFieldLstElem* pNew);
      65             :     bool SeekEntry(const _SeqFieldLstElem& rNew, size_t* pPos) const;
      66             : 
      67           0 :     size_t Count() { return maData.size(); }
      68           0 :     _SeqFieldLstElem* operator[](size_t nIndex) { return maData[nIndex]; }
      69             :     const _SeqFieldLstElem* operator[](size_t nIndex) const { return maData[nIndex]; }
      70           0 :     void Clear() { maData.clear(); }
      71             : };
      72             : 
      73        5898 : class SwGetExpFieldType : public SwValueFieldType
      74             : {
      75             : public:
      76             :         SwGetExpFieldType(SwDoc* pDoc);
      77             :         virtual SwFieldType*    Copy() const SAL_OVERRIDE;
      78             : 
      79             :         /** Overlay, because get-field cannot be changed and therefore
      80             :          does not need to be updated. Update at changing of set-values! */
      81             : protected:
      82             :    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
      83             : };
      84             : 
      85          10 : class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
      86             : {
      87             :     OUString        sExpand;
      88             :     bool            bIsInBodyText;
      89             :     sal_uInt16          nSubType;
      90             : 
      91             :     bool            bLateInitialization; // #i82544#
      92             : 
      93             :     virtual OUString            Expand() const SAL_OVERRIDE;
      94             :     virtual SwField*            Copy() const SAL_OVERRIDE;
      95             : 
      96             : public:
      97             :     SwGetExpField( SwGetExpFieldType*, const OUString& rFormel,
      98             :                    sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFormat = 0);
      99             : 
     100             :     virtual void                SetValue( const double& rVal ) SAL_OVERRIDE;
     101             :     virtual void                SetLanguage(sal_uInt16 nLng) SAL_OVERRIDE;
     102             : 
     103             :     inline OUString             GetExpStr() const;
     104             :     inline void                 ChgExpStr(const OUString& rExpand);
     105             : 
     106             :     /// Called by formatting.
     107             :     inline bool                 IsInBodyText() const;
     108             : 
     109             :     /// Set by UpdateExpFields where node position is known.
     110             :     inline void                 ChgBodyTextFlag( bool bIsInBody );
     111             : 
     112             :     /** For fields in header/footer/footnotes/flys:
     113             :      Only called by formatting!! */
     114             :     void                        ChangeExpansion( const SwFrm&, const SwTextField& );
     115             : 
     116             :     virtual OUString    GetFieldName() const SAL_OVERRIDE;
     117             : 
     118             :     /// Change formula.
     119             :     virtual OUString GetPar2() const SAL_OVERRIDE;
     120             :     virtual void        SetPar2(const OUString& rStr) SAL_OVERRIDE;
     121             : 
     122             :     virtual sal_uInt16  GetSubType() const SAL_OVERRIDE;
     123             :     virtual void        SetSubType(sal_uInt16 nType) SAL_OVERRIDE;
     124             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     125             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     126             : 
     127             :     static sal_Int32    GetReferenceTextPos( const SwFormatField& rFormat, SwDoc& rDoc, sal_Int32 nHint = 0);
     128             :     // #i82544#
     129           0 :     void                SetLateInitialization() { bLateInitialization = true;}
     130             : };
     131             : 
     132           1 : inline void SwGetExpField::ChgExpStr(const OUString& rExpand)
     133           1 :     { sExpand = rExpand;}
     134             : 
     135           1 : inline OUString SwGetExpField::GetExpStr() const
     136           1 :     { return sExpand;   }
     137             : 
     138             :  /// Called by formatting.
     139           1 : inline bool SwGetExpField::IsInBodyText() const
     140           1 :     { return bIsInBodyText; }
     141             : 
     142             :  /// Set by UpdateExpFields where node position is known.
     143           0 : inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody )
     144           0 :     { bIsInBodyText = bIsInBody; }
     145             : 
     146             : class SwSetExpField;
     147             : 
     148       23682 : class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
     149             : {
     150             :     OUString sName;
     151             :     const SwNode* pOutlChgNd;
     152             :     OUString      sDelim;
     153             :     sal_uInt16      nType;
     154             :     sal_uInt8       nLevel;
     155             :     bool        bDeleted;
     156             : 
     157             : protected:
     158             :    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
     159             : 
     160             : public:
     161             :     SwSetExpFieldType( SwDoc* pDoc, const OUString& rName,
     162             :                         sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
     163             :     virtual SwFieldType*    Copy() const SAL_OVERRIDE;
     164             :     virtual OUString        GetName() const SAL_OVERRIDE;
     165             : 
     166             :     inline void             SetType(sal_uInt16 nTyp);
     167             :     inline sal_uInt16       GetType() const;
     168             : 
     169             :     void                    SetSeqFormat(sal_uLong nFormat);
     170             :     sal_uLong               GetSeqFormat();
     171             : 
     172          97 :     bool                IsDeleted() const       { return bDeleted; }
     173           0 :     void                    SetDeleted( bool b )    { bDeleted = b; }
     174             : 
     175             :     /// Overlay, because set-field takes care for its being updated by itself.
     176             :     inline OUString         GetSetRefName() const;
     177             : 
     178             :     sal_uInt16 SetSeqRefNo( SwSetExpField& rField );
     179             : 
     180             :     size_t GetSeqFieldList( SwSeqFieldList& rList );
     181             :     OUString MakeSeqName( sal_uInt16 nSeqNo );
     182             : 
     183             :     /// Number sequence fields chapterwise if required.
     184           1 :     OUString GetDelimiter() const             { return sDelim; }
     185           9 :     void SetDelimiter( const OUString& s )    { sDelim = s; }
     186           9 :     sal_uInt8 GetOutlineLvl() const                 { return nLevel; }
     187        1158 :     void SetOutlineLvl( sal_uInt8 n )           { nLevel = n; }
     188             :     void SetChapter( SwSetExpField& rField, const SwNode& rNd );
     189             : 
     190             :     /** Member only for SwDoc::UpdateExpField.
     191             :      It is needed only at runtime of sequence field types! */
     192           3 :     const SwNode* GetOutlineChgNd() const   { return pOutlChgNd; }
     193         299 :     void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; }
     194             : 
     195             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     196             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     197             : };
     198             : 
     199         385 : inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
     200             : {
     201         385 :         nType = nTyp;
     202         385 :         EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
     203         385 : }
     204             : 
     205        2659 : inline sal_uInt16 SwSetExpFieldType::GetType() const
     206        2659 :     { return nType;   }
     207             : 
     208           1 : inline OUString SwSetExpFieldType::GetSetRefName() const
     209           1 :     { return sName; }
     210             : 
     211         668 : class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
     212             : {
     213             :     OUString        sExpand;
     214             :     OUString        aPText;
     215             :     bool            bInput;
     216             :     sal_uInt16          nSeqNo;
     217             :     sal_uInt16          nSubType;
     218             :     SwFormatField * mpFormatField; /// pool item to which the SwSetExpField belongs
     219             : 
     220             :     virtual OUString            Expand() const SAL_OVERRIDE;
     221             :     virtual SwField*            Copy() const SAL_OVERRIDE;
     222             : 
     223             : public:
     224             :     SwSetExpField(SwSetExpFieldType*, const OUString& rFormel, sal_uLong nFormat = 0);
     225             : 
     226             :     void SetFormatField(SwFormatField & rFormatField);
     227           0 :     SwFormatField* GetFormatField() { return mpFormatField;}
     228             : 
     229             :     virtual void                SetValue( const double& rVal ) SAL_OVERRIDE;
     230             : 
     231             :     inline OUString             GetExpStr() const;
     232             : 
     233             :     inline void                 ChgExpStr( const OUString& rExpand );
     234             : 
     235             :     inline void                 SetPromptText(const OUString& rStr);
     236             :     inline OUString             GetPromptText() const;
     237             : 
     238             :     inline void                 SetInputFlag(bool bInp);
     239             :     inline bool                 GetInputFlag() const;
     240             : 
     241             :     virtual OUString            GetFieldName() const SAL_OVERRIDE;
     242             : 
     243             :     virtual sal_uInt16              GetSubType() const SAL_OVERRIDE;
     244             :     virtual void                SetSubType(sal_uInt16 nType) SAL_OVERRIDE;
     245             : 
     246             :     inline bool                 IsSequenceField() const;
     247             : 
     248             :     /// Logical number, sequence fields.
     249          90 :     inline void                 SetSeqNumber( sal_uInt16 n )    { nSeqNo = n; }
     250         152 :     inline sal_uInt16           GetSeqNumber() const        { return nSeqNo; }
     251             : 
     252             :     /// Query name only.
     253             :     virtual OUString       GetPar1()   const SAL_OVERRIDE;
     254             : 
     255             :     /// Query formula.
     256             :     virtual OUString       GetPar2()   const SAL_OVERRIDE;
     257             :     virtual void                SetPar2(const OUString& rStr) SAL_OVERRIDE;
     258             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     259             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     260             : };
     261             : 
     262           4 : inline OUString SwSetExpField::GetExpStr() const
     263           4 :     { return sExpand;       }
     264             : 
     265          61 : inline void SwSetExpField::ChgExpStr( const OUString& rExpand )
     266          61 :     { sExpand = rExpand;    }
     267             : 
     268          62 : inline void  SwSetExpField::SetPromptText(const OUString& rStr)
     269          62 :     { aPText = rStr;        }
     270             : 
     271           1 : inline OUString SwSetExpField::GetPromptText() const
     272           1 :     { return aPText;        }
     273             : 
     274          62 : inline void SwSetExpField::SetInputFlag(bool bInp)
     275          62 :     { bInput = bInp; }
     276             : 
     277          48 : inline bool SwSetExpField::GetInputFlag() const
     278          48 :     { return bInput; }
     279             : 
     280         361 : inline bool SwSetExpField::IsSequenceField() const
     281         361 :     { return 0 != (nsSwGetSetExpType::GSE_SEQ & static_cast<SwSetExpFieldType*>(GetTyp())->GetType()); }
     282             : 
     283        5898 : class SwInputFieldType : public SwFieldType
     284             : {
     285             :     SwDoc* pDoc;
     286             : public:
     287             :     SwInputFieldType( SwDoc* pDoc );
     288             : 
     289             :     virtual SwFieldType* Copy() const SAL_OVERRIDE;
     290             : 
     291          19 :     SwDoc* GetDoc() const { return pDoc; }
     292             : };
     293             : 
     294             : class SW_DLLPUBLIC SwInputField : public SwField
     295             : {
     296             :     mutable OUString aContent;
     297             :     OUString aPText;
     298             :     OUString aHelp;
     299             :     OUString aToolTip;
     300             :     sal_uInt16 nSubType;
     301             :     bool mbIsFormField;
     302             : 
     303             :     SwFormatField* mpFormatField; // attribute to which the <SwInputField> belongs to
     304             : 
     305             :     virtual OUString        Expand() const SAL_OVERRIDE;
     306             :     virtual SwField*        Copy() const SAL_OVERRIDE;
     307             : 
     308             :     // Accessing Input Field's content
     309         252 :     const OUString& getContent() const { return aContent;}
     310             : 
     311             :     void LockNotifyContentChange();
     312             :     void UnlockNotifyContentChange();
     313             : 
     314             : public:
     315             :     /// Direct input via dialog; delete old value.
     316             :     SwInputField(
     317             :         SwInputFieldType* pFieldType,
     318             :         const OUString& rContent,
     319             :         const OUString& rPrompt,
     320             :         sal_uInt16 nSubType = 0,
     321             :         sal_uLong nFormat = 0,
     322             :         bool bIsFormField = true );
     323             :     virtual ~SwInputField();
     324             : 
     325             :     void SetFormatField( SwFormatField& rFormatField );
     326           0 :     SwFormatField* GetFormatField() { return mpFormatField;}
     327             : 
     328             :     // Providing new Input Field's content:
     329             :     // Fill Input Field's content depending on <nSupType>.
     330             :     void applyFieldContent( const OUString& rNewFieldContent );
     331             : 
     332             :     bool isFormField() const;
     333             : 
     334             :     virtual OUString        GetFieldName() const SAL_OVERRIDE;
     335             : 
     336             :     /// Content
     337             :     virtual OUString        GetPar1() const SAL_OVERRIDE;
     338             :     virtual void            SetPar1(const OUString& rStr) SAL_OVERRIDE;
     339             : 
     340             :     /// aPromptText
     341             :     virtual OUString        GetPar2() const SAL_OVERRIDE;
     342             :     virtual void            SetPar2(const OUString& rStr) SAL_OVERRIDE;
     343             : 
     344             :     OUString        GetHelp() const;
     345             :     void            SetHelp(const OUString & rStr);
     346             : 
     347             :     OUString        GetToolTip() const;
     348             :     void            SetToolTip(const OUString & rStr);
     349             : 
     350             :     virtual sal_uInt16      GetSubType() const SAL_OVERRIDE;
     351             :     virtual void            SetSubType(sal_uInt16 nSub) SAL_OVERRIDE;
     352             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     353             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     354             : };
     355             : 
     356             : // Sorted list of input fields and DropDown fields
     357             : class SwInputFieldList
     358             : {
     359             : public:
     360             :     SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst = false );
     361             :     ~SwInputFieldList();
     362             : 
     363             :     size_t      Count() const;
     364             :     SwField*    GetField(size_t nId);
     365             : 
     366             :     void        GotoFieldPos(size_t nId);
     367             :     void        PushCrsr();
     368             :     void        PopCrsr();
     369             : 
     370             :     /** Put all that are new into SortLst for updating. @return true if not empty.
     371             :      (For Glossary: only update its input-fields).
     372             :      Compare TmpLst with current fields. */
     373             :     bool        BuildSortLst();
     374             : 
     375             : private:
     376             :     SwEditShell*              pSh;
     377             :     _SetGetExpFields*           pSrtLst;
     378             :     std::set<const SwTextField*> aTmpLst;
     379             : };
     380             : 
     381             :  /// Implementation in tblcalc.cxx.
     382        5898 : class SwTableFieldType : public SwValueFieldType
     383             : {
     384             : public:
     385             :     SwTableFieldType(SwDoc* pDocPtr);
     386             :     virtual SwFieldType* Copy() const SAL_OVERRIDE;
     387             : };
     388             : 
     389           0 : class SwTableField : public SwValueField, public SwTableFormula
     390             : {
     391             :     OUString      sExpand;
     392             :     sal_uInt16      nSubType;
     393             : 
     394             :     virtual OUString    Expand() const SAL_OVERRIDE;
     395             :     virtual SwField*    Copy() const SAL_OVERRIDE;
     396             : 
     397             :     /// Search TextNode containing the field.
     398             :     virtual const SwNode* GetNodeOfFormula() const SAL_OVERRIDE;
     399             : 
     400             :     OUString GetCommand();
     401             : 
     402             : public:
     403             :     SwTableField( SwTableFieldType*, const OUString& rFormel,
     404             :                 sal_uInt16 nSubType = 0, sal_uLong nFormat = 0);
     405             : 
     406             :     virtual void        SetValue( const double& rVal ) SAL_OVERRIDE;
     407             :     virtual sal_uInt16      GetSubType() const SAL_OVERRIDE;
     408             :     virtual void        SetSubType(sal_uInt16 nType) SAL_OVERRIDE;
     409             : 
     410           0 :     OUString            GetExpStr() const               { return sExpand; }
     411           0 :     void                ChgExpStr(const OUString& rStr) { sExpand = rStr; }
     412             : 
     413             :     void                CalcField( SwTableCalcPara& rCalcPara );
     414             : 
     415             :     virtual OUString    GetFieldName() const SAL_OVERRIDE;
     416             : 
     417             :     /// The formula.
     418             :     virtual OUString GetPar2()   const SAL_OVERRIDE;
     419             :     virtual void        SetPar2(const OUString& rStr) SAL_OVERRIDE;
     420             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     421             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     422             : };
     423             : 
     424             : #endif // INCLUDED_SW_INC_EXPFLD_HXX
     425             : 
     426             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11