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

Generated by: LCOV version 1.10