LCOV - code coverage report
Current view: top level - sw/inc - expfld.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 67 64.2 %
Date: 2014-11-03 Functions: 34 52 65.4 %
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 SwTxtNode;
      30             : class SwFrm;
      31             : struct SwPosition;
      32             : class SwTxtFld;
      33             : class SwDoc;
      34             : class SwFmtFld;
      35             : class _SetGetExpFlds;
      36             : class SwEditShell;
      37             : 
      38             : /// Forward declaration: get "BodyTxtNode" for exp.fld in Fly's headers/footers/footnotes.
      39             : const SwTxtNode* GetBodyTxtNode( const SwDoc& pDoc, SwPosition& rPos,
      40             :                                  const SwFrm& rFrm );
      41             : 
      42             : OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false);
      43             : 
      44           0 : struct _SeqFldLstElem
      45             : {
      46             :     OUString sDlgEntry;
      47             :     sal_uInt16 nSeqNo;
      48             : 
      49           0 :     _SeqFldLstElem( const OUString& rStr, sal_uInt16 nNo )
      50           0 :         : sDlgEntry( rStr ), nSeqNo( nNo )
      51           0 :     {}
      52             : };
      53             : 
      54           0 : class SW_DLLPUBLIC SwSeqFldList
      55             : {
      56             :     std::vector<_SeqFldLstElem*> maData;
      57             : public:
      58           0 :     ~SwSeqFldList()
      59           0 :     {
      60           0 :         for( std::vector<_SeqFldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it )
      61           0 :             delete *it;
      62           0 :     }
      63             : 
      64             :     bool InsertSort(_SeqFldLstElem* pNew);
      65             :     bool SeekEntry(const _SeqFldLstElem& rNew, size_t* pPos) const;
      66             : 
      67           0 :     size_t Count() { return maData.size(); }
      68           0 :     _SeqFldLstElem* operator[](size_t nIndex) { return maData[nIndex]; }
      69             :     const _SeqFldLstElem* operator[](size_t nIndex) const { return maData[nIndex]; }
      70           0 :     void Clear() { maData.clear(); }
      71             : };
      72             : 
      73       10090 : 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          20 : class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
      86             : {
      87             :     OUString        sExpand;
      88             :     bool            bIsInBodyTxt;
      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 nFmt = 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                 IsInBodyTxt() const;
     108             : 
     109             :     /// Set by UpdateExpFlds where node position is known.
     110             :     inline void                 ChgBodyTxtFlag( bool bIsInBody );
     111             : 
     112             :     /** For fields in header/footer/footnotes/flys:
     113             :      Only called by formatting!! */
     114             :     void                        ChangeExpansion( const SwFrm&, const SwTxtFld& );
     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 SwFmtFld& rFmt, SwDoc& rDoc, sal_Int32 nHint = 0);
     128             :     // #i82544#
     129           0 :     void                SetLateInitialization() { bLateInitialization = true;}
     130             : };
     131             : 
     132           2 : inline void SwGetExpField::ChgExpStr(const OUString& rExpand)
     133           2 :     { sExpand = rExpand;}
     134             : 
     135           2 : inline OUString SwGetExpField::GetExpStr() const
     136           2 :     { return sExpand;   }
     137             : 
     138             :  /// Called by formatting.
     139           2 : inline bool SwGetExpField::IsInBodyTxt() const
     140           2 :     { return bIsInBodyTxt; }
     141             : 
     142             :  /// Set by UpdateExpFlds where node position is known.
     143           0 : inline void SwGetExpField::ChgBodyTxtFlag( bool bIsInBody )
     144           0 :     { bIsInBodyTxt = bIsInBody; }
     145             : 
     146             : class SwSetExpField;
     147             : 
     148       40474 : 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         158 :     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& rFld );
     179             : 
     180             :     size_t GetSeqFldList( SwSeqFldList& rList );
     181             :     OUString MakeSeqName( sal_uInt16 nSeqNo );
     182             : 
     183             :     /// Number sequence fields chapterwise if required.
     184           0 :     OUString GetDelimiter() const             { return sDelim; }
     185           6 :     void SetDelimiter( const OUString& s )    { sDelim = s; }
     186           0 :     sal_uInt8 GetOutlineLvl() const                 { return nLevel; }
     187        1228 :     void SetOutlineLvl( sal_uInt8 n )           { nLevel = n; }
     188             :     void SetChapter( SwSetExpField& rFld, const SwNode& rNd );
     189             : 
     190             :     /** Member only for SwDoc::UpdateExpFld.
     191             :      It is needed only at runtime of sequence field types! */
     192           0 :     const SwNode* GetOutlineChgNd() const   { return pOutlChgNd; }
     193          94 :     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         594 : inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
     200             : {
     201         594 :         nType = nTyp;
     202         594 :         EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
     203         594 : }
     204             : 
     205        3172 : inline sal_uInt16 SwSetExpFieldType::GetType() const
     206        3172 :     { return nType;   }
     207             : 
     208           2 : inline OUString SwSetExpFieldType::GetSetRefName() const
     209           2 :     { return sName; }
     210             : 
     211        1056 : 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             :     SwFmtFld * mpFmtFld; /// 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 nFmt = 0);
     225             : 
     226             :     void SetFmtFld(SwFmtFld & rFmtFld);
     227           0 :     SwFmtFld* GetFmtFld() { return mpFmtFld;}
     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                 IsSequenceFld() const;
     247             : 
     248             :     /// Logical number, sequence fields.
     249         144 :     inline void                 SetSeqNumber( sal_uInt16 n )    { nSeqNo = n; }
     250         260 :     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           2 : inline OUString SwSetExpField::GetExpStr() const
     263           2 :     { return sExpand;       }
     264             : 
     265          92 : inline void SwSetExpField::ChgExpStr( const OUString& rExpand )
     266          92 :     { sExpand = rExpand;    }
     267             : 
     268         100 : inline void  SwSetExpField::SetPromptText(const OUString& rStr)
     269         100 :     { aPText = rStr;        }
     270             : 
     271           2 : inline OUString SwSetExpField::GetPromptText() const
     272           2 :     { return aPText;        }
     273             : 
     274         100 : inline void SwSetExpField::SetInputFlag(bool bInp)
     275         100 :     { bInput = bInp; }
     276             : 
     277          58 : inline bool SwSetExpField::GetInputFlag() const
     278          58 :     { return bInput; }
     279             : 
     280         538 : inline bool SwSetExpField::IsSequenceFld() const
     281         538 :     { return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); }
     282             : 
     283       10090 : class SwInputFieldType : public SwFieldType
     284             : {
     285             :     SwDoc* pDoc;
     286             : public:
     287             :     SwInputFieldType( SwDoc* pDoc );
     288             : 
     289             :     virtual SwFieldType* Copy() const SAL_OVERRIDE;
     290             : 
     291          44 :     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             :     SwFmtFld* mpFmtFld; // 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         342 :     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 nFmt = 0,
     322             :         bool bIsFormField = true );
     323             :     virtual ~SwInputField();
     324             : 
     325             :     void SetFmtFld( SwFmtFld& rFmtFld );
     326          32 :     SwFmtFld* GetFmtFld() { return mpFmtFld;}
     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             :     virtual OUString        GetHelp() const;
     345             :     virtual void            SetHelp(const OUString & rStr);
     346             : 
     347             :     virtual OUString        GetToolTip() const;
     348             :     virtual 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             :     _SetGetExpFlds*           pSrtLst;
     378             :     std::set<const SwTxtFld*> aTmpLst;
     379             : };
     380             : 
     381             :  /// Implementation in tblcalc.cxx.
     382       10090 : class SwTblFieldType : public SwValueFieldType
     383             : {
     384             : public:
     385             :     SwTblFieldType(SwDoc* pDocPtr);
     386             :     virtual SwFieldType* Copy() const SAL_OVERRIDE;
     387             : };
     388             : 
     389           0 : class SwTblField : 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             :     SwTblField( SwTblFieldType*, const OUString& rFormel,
     404             :                 sal_uInt16 nSubType = 0, sal_uLong nFmt = 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( SwTblCalcPara& 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.10