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

Generated by: LCOV version 1.10