LCOV - code coverage report
Current view: top level - sw/inc - section.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 87 98 88.8 %
Date: 2015-06-13 12:38:46 Functions: 54 64 84.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             : 
      20             : #ifndef INCLUDED_SW_INC_SECTION_HXX
      21             : #define INCLUDED_SW_INC_SECTION_HXX
      22             : 
      23             : #include <com/sun/star/uno/Sequence.h>
      24             : 
      25             : #include <tools/rtti.hxx>
      26             : #include <tools/ref.hxx>
      27             : #include <svl/smplhint.hxx>
      28             : #include <sfx2/lnkbase.hxx>
      29             : #include <sfx2/Metadatable.hxx>
      30             : 
      31             : #include <frmfmt.hxx>
      32             : #include <vector>
      33             : 
      34             : namespace com { namespace sun { namespace star {
      35             :     namespace text { class XTextSection; }
      36             : } } }
      37             : 
      38             : class SwSectionFormat;
      39             : class SwDoc;
      40             : class SwSection;
      41             : class SwSectionNode;
      42             : class SwTOXBase;
      43             : class SwServerObject;
      44             : 
      45             : typedef std::vector<SwSection*> SwSections;
      46             : 
      47             : enum SectionType { CONTENT_SECTION,
      48             :                     TOX_HEADER_SECTION,
      49             :                     TOX_CONTENT_SECTION,
      50             :                     DDE_LINK_SECTION    = OBJECT_CLIENT_DDE,
      51             :                     FILE_LINK_SECTION   = OBJECT_CLIENT_FILE
      52             :                     };
      53             : 
      54             : enum LinkCreateType
      55             : {
      56             :     CREATE_NONE,            // Do nothing.
      57             :     CREATE_CONNECT,         // Connect created link.
      58             :     CREATE_UPDATE           // Connect created link and update it.
      59             : };
      60             : 
      61         847 : class SW_DLLPUBLIC SwSectionData
      62             : {
      63             : private:
      64             :     SectionType m_eType;
      65             : 
      66             :     OUString m_sSectionName;
      67             :     OUString m_sCondition;
      68             :     OUString m_sLinkFileName;
      69             :     OUString m_sLinkFilePassword; // Must be changed to Sequence.
      70             :     ::com::sun::star::uno::Sequence <sal_Int8> m_Password;
      71             : 
      72             :     /// It seems this flag caches the current final "hidden" state.
      73             :     bool m_bHiddenFlag          : 1;
      74             :     /// Flags that correspond to attributes in the format:
      75             :     /// may have different value than format attribute:
      76             :     /// format attr has value for this section, while flag is
      77             :     /// effectively ORed with parent sections!
      78             :     bool m_bProtectFlag         : 1;
      79             :     // Edit in readonly sections.
      80             :     bool m_bEditInReadonlyFlag  : 1;
      81             : 
      82             :     bool m_bHidden              : 1; // All paragraphs hidden?
      83             :     bool m_bCondHiddenFlag      : 1; // Hiddenflag for condition.
      84             :     bool m_bConnectFlag         : 1; // Connected to server?
      85             : 
      86             : public:
      87             : 
      88             :     SwSectionData(SectionType const eType, OUString const& rName);
      89             :     explicit SwSectionData(SwSection const&);
      90             :     SwSectionData(SwSectionData const&);
      91             :     SwSectionData & operator=(SwSectionData const&);
      92             :     bool operator==(SwSectionData const&) const;
      93             : 
      94        1508 :     OUString GetSectionName() const         { return m_sSectionName; }
      95         125 :     void SetSectionName(OUString const& rName){ m_sSectionName = rName; }
      96        6253 :     SectionType GetType() const             { return m_eType; }
      97           8 :     void SetType(SectionType const eNew)    { m_eType = eNew; }
      98             : 
      99        2427 :     bool IsHidden() const { return m_bHidden; }
     100         203 :     void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; }
     101             : 
     102        1872 :     bool IsHiddenFlag() const { return m_bHiddenFlag; }
     103             :     SAL_DLLPRIVATE void
     104         446 :         SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
     105        1020 :     bool IsProtectFlag() const { return m_bProtectFlag; }
     106             :     SAL_DLLPRIVATE void
     107        1317 :         SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
     108         863 :     bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
     109        1193 :     void SetEditInReadonlyFlag(bool const bFlag)
     110        1193 :         { m_bEditInReadonlyFlag = bFlag; }
     111             : 
     112          10 :     void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; }
     113         220 :     bool IsCondHidden() const { return m_bCondHiddenFlag; }
     114             : 
     115         224 :     OUString GetCondition() const           { return m_sCondition; }
     116         206 :     void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
     117             : 
     118         314 :     OUString GetLinkFileName() const        { return m_sLinkFileName; }
     119         214 :     void SetLinkFileName(OUString const& rNew, OUString const* pPassWd = 0)
     120             :     {
     121         214 :         m_sLinkFileName = rNew;
     122         214 :         if (pPassWd) { SetLinkFilePassword(*pPassWd); }
     123         214 :     }
     124             : 
     125         150 :     OUString GetLinkFilePassword() const        { return m_sLinkFilePassword; }
     126           0 :     void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
     127             : 
     128         171 :     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
     129         171 :                                             { return m_Password; }
     130           2 :     void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew)
     131           2 :                                             { m_Password = rNew; }
     132         343 :     bool IsLinkType() const
     133         343 :     { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
     134             : 
     135         150 :     bool IsConnectFlag() const                  { return m_bConnectFlag; }
     136           1 :     void SetConnectFlag(bool const bFlag = true){ m_bConnectFlag = bFlag; }
     137             : 
     138             :     static OUString CollapseWhiteSpaces(const OUString& sName);
     139             : };
     140             : 
     141             : class SW_DLLPUBLIC SwSection
     142             :     : public SwClient
     143             : {
     144             :     // In order to correctly maintain the flag when creating/deleting frames.
     145             :     friend class SwSectionNode;
     146             :     // The "read CTOR" of SwSectionFrm have to change the Hiddenflag.
     147             :     friend class SwSectionFrm;
     148             : 
     149             : private:
     150             :     mutable SwSectionData m_Data;
     151             : 
     152             :     tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
     153             :     ::sfx2::SvBaseLinkRef m_RefLink;
     154             : 
     155             :     SAL_DLLPRIVATE void ImplSetHiddenFlag(
     156             :             bool const bHidden, bool const bCondition);
     157             : 
     158             : protected:
     159             :     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) SAL_OVERRIDE;
     160             : 
     161             : public:
     162             :     TYPEINFO_OVERRIDE();     // rtti
     163             : 
     164             :     SwSection(SectionType const eType, OUString const& rName,
     165             :                 SwSectionFormat & rFormat);
     166             :     virtual ~SwSection();
     167             : 
     168             :     bool DataEquals(SwSectionData const& rCmp) const;
     169             : 
     170             :     void SetSectionData(SwSectionData const& rData);
     171             : 
     172        1504 :     OUString GetSectionName() const         { return m_Data.GetSectionName(); }
     173         125 :     void SetSectionName(OUString const& rName){ m_Data.SetSectionName(rName); }
     174        6081 :     SectionType GetType() const             { return m_Data.GetType(); }
     175           6 :     void SetType(SectionType const eType)   { return m_Data.SetType(eType); }
     176             : 
     177             :     inline SwSectionFormat* GetFormat();
     178             :     inline SwSectionFormat const * GetFormat() const;
     179             : 
     180             :     // Set hidden/protected -> update the whole tree!
     181             :     // (Attributes/flags are set/get.)
     182        1041 :     bool IsHidden()  const { return m_Data.IsHidden(); }
     183             :     void SetHidden (bool const bFlag = true);
     184             :     bool IsProtect() const;
     185             :     void SetProtect(bool const bFlag = true);
     186             :     bool IsEditInReadonly() const;
     187             :     void SetEditInReadonly(bool const bFlag = true);
     188             : 
     189             :     // Get internal flags (state including parents, not what is
     190             :     // currently set at section!).
     191        1836 :     bool IsHiddenFlag()  const { return m_Data.IsHiddenFlag(); }
     192         198 :     bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
     193          41 :     bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
     194             : 
     195             :     void SetCondHidden(bool const bFlag = true);
     196         168 :     bool IsCondHidden() const { return m_Data.IsCondHidden(); }
     197             :     // Query (also for parents) if this section is to be hidden.
     198             :     bool CalcHiddenFlag() const;
     199             : 
     200             :     inline SwSection* GetParent() const;
     201             : 
     202         206 :     OUString GetCondition() const           { return m_Data.GetCondition(); }
     203           8 :     void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
     204             : 
     205             :     OUString GetLinkFileName() const;
     206             :     void SetLinkFileName(OUString const& rNew, OUString const*const pPassWd = 0);
     207             :     // Password of linked file (only valid during runtime!)
     208         150 :     OUString GetLinkFilePassword() const
     209         150 :         { return m_Data.GetLinkFilePassword(); }
     210           0 :     void SetLinkFilePassword(OUString const& rS)
     211           0 :         { m_Data.SetLinkFilePassword(rS); }
     212             : 
     213             :     // Get / set password of this section
     214         171 :     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
     215         171 :                                             { return m_Data.GetPassword(); }
     216             :     void SetPassword(::com::sun::star::uno::Sequence <sal_Int8> const& rNew)
     217             :                                             { m_Data.SetPassword(rNew); }
     218             : 
     219             :     // Data server methods.
     220             :     void SetRefObject( SwServerObject* pObj );
     221             :     const SwServerObject* GetObject() const {  return & m_RefObj; }
     222           0 :           SwServerObject* GetObject()       {  return & m_RefObj; }
     223          10 :     bool IsServer() const                   {  return m_RefObj.Is(); }
     224             : 
     225             :     // Methods for linked ranges.
     226           0 :     SfxLinkUpdateMode GetUpdateType() const    { return m_RefLink->GetUpdateMode(); }
     227           0 :     void SetUpdateType(SfxLinkUpdateMode nType )
     228           0 :         { m_RefLink->SetUpdateMode(nType); }
     229             : 
     230           7 :     bool IsConnected() const        { return m_RefLink.Is(); }
     231           0 :     void UpdateNow()                { m_RefLink->Update(); }
     232           0 :     void Disconnect()               { m_RefLink->Disconnect(); }
     233             : 
     234           0 :     const ::sfx2::SvBaseLink& GetBaseLink() const    { return *m_RefLink; }
     235           0 :           ::sfx2::SvBaseLink& GetBaseLink()          { return *m_RefLink; }
     236             : 
     237             :     void CreateLink( LinkCreateType eType );
     238             : 
     239             :     static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
     240             : 
     241          10 :     bool IsLinkType() const { return m_Data.IsLinkType(); }
     242             : 
     243             :     // Flags for UI. Did connection work?
     244         150 :     bool IsConnectFlag() const      { return m_Data.IsConnectFlag(); }
     245           1 :     void SetConnectFlag(bool const bFlag = true)
     246           1 :                                     { m_Data.SetConnectFlag(bFlag); }
     247             : 
     248             :     // Return the TOX base class if the section is a TOX section
     249             :     const SwTOXBase* GetTOXBase() const;
     250             : 
     251             :     void BreakLink();
     252             : 
     253             : };
     254             : 
     255             : // #i117863#
     256             : class SwSectionFrmMoveAndDeleteHint : public SfxSimpleHint
     257             : {
     258             :     public:
     259         392 :         SwSectionFrmMoveAndDeleteHint( const bool bSaveContent )
     260             :             : SfxSimpleHint( SFX_HINT_DYING )
     261         392 :             , mbSaveContent( bSaveContent )
     262         392 :         {}
     263             : 
     264         392 :         virtual ~SwSectionFrmMoveAndDeleteHint()
     265         392 :         {}
     266             : 
     267          14 :         bool IsSaveContent() const
     268             :         {
     269          14 :             return mbSaveContent;
     270             :         }
     271             : 
     272             :     private:
     273             :         const bool mbSaveContent;
     274             : };
     275             : 
     276             : enum SectionSort { SORTSECT_NOT, SORTSECT_NAME, SORTSECT_POS };
     277             : 
     278             : class SW_DLLPUBLIC SwSectionFormat
     279             :     : public SwFrameFormat
     280             :     , public ::sfx2::Metadatable
     281             : {
     282             :     friend class SwDoc;
     283             : 
     284             :     /** Why does this exist in addition to the m_wXObject in SwFrameFormat?
     285             :         in case of an index, both a SwXDocumentIndex and a SwXTextSection
     286             :         register at this SwSectionFormat, so we need to have two refs.
     287             :      */
     288             :     ::com::sun::star::uno::WeakReference<
     289             :         ::com::sun::star::text::XTextSection> m_wXTextSection;
     290             : 
     291             :     SAL_DLLPRIVATE void UpdateParent();      // Parent has been changed.
     292             : 
     293             : protected:
     294             :     SwSectionFormat( SwFrameFormat* pDrvdFrm, SwDoc *pDoc );
     295             :    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) SAL_OVERRIDE;
     296             : 
     297             : public:
     298             :     TYPEINFO_OVERRIDE();     // Already contained in base class client.
     299             :     virtual ~SwSectionFormat();
     300             : 
     301             :     // Deletes all Frms in aDepend (Frms are recognized via PTR_CAST).
     302             :     virtual void DelFrms() SAL_OVERRIDE;
     303             : 
     304             :     // Creates views.
     305             :     virtual void MakeFrms() SAL_OVERRIDE;
     306             : 
     307             :     // Get information from Format.
     308             :     virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE;
     309             : 
     310             :     SwSection* GetSection() const;
     311             :     inline SwSectionFormat* GetParent() const;
     312             :     inline SwSection* GetParentSection() const;
     313             : 
     314             :     //  All sections that are derived from this one:
     315             :     //  - sorted according to name or position or unsorted
     316             :     //  - all of them or only those that are in the normal Nodes-array.
     317             :     void GetChildSections( SwSections& rArr,
     318             :                             SectionSort eSort = SORTSECT_NOT,
     319             :                             bool bAllSections = true ) const;
     320             : 
     321             :     // Query whether section is in Nodes-array or in UndoNodes-array.
     322             :     bool IsInNodesArr() const;
     323             : 
     324             :           SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false);
     325         100 :     const SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false) const
     326             :         { return const_cast<SwSectionFormat *>(this)
     327         100 :                 ->GetSectionNode(bEvenIfInUndo); }
     328             : 
     329             :     // Is section a valid one for global document?
     330             :     const SwSection* GetGlobalDocSection() const;
     331             : 
     332             :     SAL_DLLPRIVATE ::com::sun::star::uno::WeakReference<
     333         252 :         ::com::sun::star::text::XTextSection> const& GetXTextSection() const
     334         252 :             { return m_wXTextSection; }
     335         107 :     SAL_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference<
     336             :                     ::com::sun::star::text::XTextSection> const& xTextSection)
     337         107 :             { m_wXTextSection = xTextSection; }
     338             : 
     339             :     // sfx2::Metadatable
     340             :     virtual ::sfx2::IXmlIdRegistry& GetRegistry() SAL_OVERRIDE;
     341             :     virtual bool IsInClipboard() const SAL_OVERRIDE;
     342             :     virtual bool IsInUndo() const SAL_OVERRIDE;
     343             :     virtual bool IsInContent() const SAL_OVERRIDE;
     344             :     virtual ::com::sun::star::uno::Reference<
     345             :         ::com::sun::star::rdf::XMetadatable > MakeUnoObject() SAL_OVERRIDE;
     346             :     void dumpAsXml(struct _xmlTextWriter* pWriter) const;
     347             : 
     348             : };
     349             : 
     350        8588 : SwSectionFormat* SwSection::GetFormat()
     351             : {
     352        8588 :     return static_cast<SwSectionFormat*>(GetRegisteredIn());
     353             : }
     354             : 
     355        2969 : SwSectionFormat const * SwSection::GetFormat() const
     356             : {
     357        2969 :     return static_cast<SwSectionFormat const *>(GetRegisteredIn());
     358             : }
     359             : 
     360        1130 : inline SwSection* SwSection::GetParent() const
     361             : {
     362        1130 :     SwSectionFormat const * pFormat = GetFormat();
     363        1130 :     SwSection* pRet = 0;
     364        1130 :     if( pFormat )
     365        1130 :         pRet = pFormat->GetParentSection();
     366        1130 :     return pRet;
     367             : }
     368             : 
     369        1246 : inline SwSectionFormat* SwSectionFormat::GetParent() const
     370             : {
     371        1246 :     SwSectionFormat* pRet = 0;
     372        1246 :     if( GetRegisteredIn() )
     373        1246 :         pRet = const_cast<SwSectionFormat*>(PTR_CAST( SwSectionFormat, GetRegisteredIn() ));
     374        1246 :     return pRet;
     375             : }
     376             : 
     377        1140 : inline SwSection* SwSectionFormat::GetParentSection() const
     378             : {
     379        1140 :     SwSectionFormat* pParent = GetParent();
     380        1140 :     SwSection* pRet = 0;
     381        1140 :     if( pParent )
     382             :     {
     383         161 :         pRet = pParent->GetSection();
     384             :     }
     385        1140 :     return pRet;
     386             : }
     387             : 
     388             : #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11