LCOV - code coverage report
Current view: top level - sw/inc - section.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 85 96 88.5 %
Date: 2014-11-03 Functions: 55 64 85.9 %
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 SwSectionFmt;
      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        1762 : 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        3104 :     OUString GetSectionName() const         { return m_sSectionName; }
      95         278 :     void SetSectionName(OUString const& rName){ m_sSectionName = rName; }
      96        9840 :     SectionType GetType() const             { return m_eType; }
      97          34 :     void SetType(SectionType const eNew)    { m_eType = eNew; }
      98             : 
      99        4652 :     bool IsHidden() const { return m_bHidden; }
     100         312 :     void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; }
     101             : 
     102        3492 :     bool IsHiddenFlag() const { return m_bHiddenFlag; }
     103             :     SAL_DLLPRIVATE void
     104         852 :         SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
     105        2047 :     bool IsProtectFlag() const { return m_bProtectFlag; }
     106             :     SAL_DLLPRIVATE void
     107        2538 :         SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
     108        1678 :     bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
     109        2302 :     void SetEditInReadonlyFlag(bool const bFlag)
     110        2302 :         { m_bEditInReadonlyFlag = bFlag; }
     111             : 
     112          22 :     void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; }
     113         506 :     bool IsCondHidden() const { return m_bCondHiddenFlag; }
     114             : 
     115         686 :     OUString GetCondition() const           { return m_sCondition; }
     116         332 :     void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
     117             : 
     118        1196 :     OUString GetLinkFileName() const        { return m_sLinkFileName; }
     119         662 :     void SetLinkFileName(OUString const& rNew, OUString const* pPassWd = 0)
     120             :     {
     121         662 :         m_sLinkFileName = rNew;
     122         662 :         if (pPassWd) { SetLinkFilePassword(*pPassWd); }
     123         662 :     }
     124             : 
     125         564 :     OUString GetLinkFilePassword() const        { return m_sLinkFilePassword; }
     126           0 :     void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
     127             : 
     128         570 :     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
     129         570 :                                             { return m_Password; }
     130           8 :     void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew)
     131           8 :                                             { m_Password = rNew; }
     132         680 :     bool IsLinkType() const
     133         680 :     { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
     134             : 
     135         542 :     bool IsConnectFlag() const                  { return m_bConnectFlag; }
     136          32 :     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             :                 SwSectionFmt & rFormat);
     166             :     virtual ~SwSection();
     167             : 
     168             :     bool DataEquals(SwSectionData const& rCmp) const;
     169             : 
     170             :     void SetSectionData(SwSectionData const& rData);
     171             : 
     172        3054 :     OUString GetSectionName() const         { return m_Data.GetSectionName(); }
     173         264 :     void SetSectionName(OUString const& rName){ m_Data.SetSectionName(rName); }
     174        9116 :     SectionType GetType() const             { return m_Data.GetType(); }
     175          24 :     void SetType(SectionType const eType)   { return m_Data.SetType(eType); }
     176             : 
     177       15828 :     SwSectionFmt* GetFmt()          { return (SwSectionFmt*)GetRegisteredIn(); }
     178        7392 :     SwSectionFmt* GetFmt() const    { return (SwSectionFmt*)GetRegisteredIn(); }
     179             : 
     180             :     // Set hidden/protected -> update the whole tree!
     181             :     // (Attributes/flags are set/get.)
     182        2214 :     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        3444 :     bool IsHiddenFlag()  const { return m_Data.IsHiddenFlag(); }
     192         459 :     bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
     193          90 :     bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
     194             : 
     195             :     void SetCondHidden(bool const bFlag = true);
     196         424 :     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         678 :     OUString GetCondition() const           { return m_Data.GetCondition(); }
     203          28 :     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         564 :     OUString GetLinkFilePassword() const
     209         564 :         { 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         570 :     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
     215         570 :                                             { 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          32 :     bool IsServer() const                   {  return m_RefObj.Is(); }
     224             : 
     225             :     // Methods for linked ranges.
     226           4 :     sal_uInt16 GetUpdateType() const    { return m_RefLink->GetUpdateMode(); }
     227           0 :     void SetUpdateType(sal_uInt16 const nType )
     228           0 :         { m_RefLink->SetUpdateMode(nType); }
     229             : 
     230          48 :     bool IsConnected() const        { return m_RefLink.Is(); }
     231           0 :     void UpdateNow()                { m_RefLink->Update(); }
     232           0 :     void Disconnect()               { m_RefLink->Disconnect(); }
     233             : 
     234          14 :     const ::sfx2::SvBaseLink& GetBaseLink() const    { return *m_RefLink; }
     235           0 :           ::sfx2::SvBaseLink& GetBaseLink()          { return *m_RefLink; }
     236             : 
     237             :     void CreateLink( LinkCreateType eType );
     238             : 
     239             :     void MakeChildLinksVisible( const SwSectionNode& rSectNd );
     240             : 
     241         110 :     bool IsLinkType() const { return m_Data.IsLinkType(); }
     242             : 
     243             :     // Flags for UI. Did connection work?
     244         542 :     bool IsConnectFlag() const      { return m_Data.IsConnectFlag(); }
     245          32 :     void SetConnectFlag(bool const bFlag = true)
     246          32 :                                     { 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         668 :         SwSectionFrmMoveAndDeleteHint( const bool bSaveCntnt )
     260             :             : SfxSimpleHint( SFX_HINT_DYING )
     261         668 :             , mbSaveCntnt( bSaveCntnt )
     262         668 :         {}
     263             : 
     264         668 :         virtual ~SwSectionFrmMoveAndDeleteHint()
     265         668 :         {}
     266             : 
     267          34 :         bool IsSaveCntnt() const
     268             :         {
     269          34 :             return mbSaveCntnt;
     270             :         }
     271             : 
     272             :     private:
     273             :         const bool mbSaveCntnt;
     274             : };
     275             : 
     276             : enum SectionSort { SORTSECT_NOT, SORTSECT_NAME, SORTSECT_POS };
     277             : 
     278             : class SW_DLLPUBLIC SwSectionFmt
     279             :     : public SwFrmFmt
     280             :     , public ::sfx2::Metadatable
     281             : {
     282             :     friend class SwDoc;
     283             : 
     284             :     /** Why does this exist in addition to the m_wXObject in SwFrmFmt?
     285             :         in case of an index, both a SwXDocumentIndex and a SwXTextSection
     286             :         register at this SwSectionFmt, 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             :     SwSectionFmt( SwFrmFmt* 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 ~SwSectionFmt();
     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 SwSectionFmt* 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             :     sal_uInt16 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           0 :     const SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false) const
     326             :         { return const_cast<SwSectionFmt *>(this)
     327           0 :                 ->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         392 :         ::com::sun::star::text::XTextSection> const& GetXTextSection() const
     334         392 :             { return m_wXTextSection; }
     335         190 :     SAL_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference<
     336             :                     ::com::sun::star::text::XTextSection> const& xTextSection)
     337         190 :             { 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             : 
     347             : };
     348             : 
     349        2004 : inline SwSection* SwSection::GetParent() const
     350             : {
     351        2004 :     SwSectionFmt* pFmt = GetFmt();
     352        2004 :     SwSection* pRet = 0;
     353        2004 :     if( pFmt )
     354        2004 :         pRet = pFmt->GetParentSection();
     355        2004 :     return pRet;
     356             : }
     357             : 
     358        2166 : inline SwSectionFmt* SwSectionFmt::GetParent() const
     359             : {
     360        2166 :     SwSectionFmt* pRet = 0;
     361        2166 :     if( GetRegisteredIn() )
     362        2166 :         pRet = const_cast<SwSectionFmt*>(PTR_CAST( SwSectionFmt, GetRegisteredIn() ));
     363        2166 :     return pRet;
     364             : }
     365             : 
     366        2020 : inline SwSection* SwSectionFmt::GetParentSection() const
     367             : {
     368        2020 :     SwSectionFmt* pParent = GetParent();
     369        2020 :     SwSection* pRet = 0;
     370        2020 :     if( pParent )
     371             :     {
     372         310 :         pRet = pParent->GetSection();
     373             :     }
     374        2020 :     return pRet;
     375             : }
     376             : 
     377             : #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
     378             : 
     379             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10