bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / section.hxx
blob77fdd2a8bcf1a50a0f8cea9178f1822583805aad
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SECTION_HXX
21 #define _SECTION_HXX
23 #include <boost/utility.hpp>
25 #include <com/sun/star/uno/Sequence.h>
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>
33 #include <frmfmt.hxx>
34 #include <vector>
37 namespace com { namespace sun { namespace star {
38 namespace text { class XTextSection; }
39 } } }
42 class SwSectionFmt;
43 class SwDoc;
44 class SwSection;
45 class SwSectionNode;
46 class SwTOXBase;
48 #ifndef SW_DECL_SWSERVEROBJECT_DEFINED
49 #define SW_DECL_SWSERVEROBJECT_DEFINED
50 SV_DECL_REF( SwServerObject )
51 #endif
53 typedef std::vector<SwSection*> SwSections;
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
62 enum LinkCreateType
64 CREATE_NONE, // Do nothing.
65 CREATE_CONNECT, // Connect created link.
66 CREATE_UPDATE // Connect created link and update it.
69 class SW_DLLPUBLIC SwSectionData
71 private:
72 SectionType m_eType;
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;
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;
90 bool m_bHidden : 1; // All paragraphs hidden?
91 bool m_bCondHiddenFlag : 1; // Hiddenflag for condition.
92 bool m_bConnectFlag : 1; // Connected to server?
94 public:
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;
102 String const& GetSectionName() const { return m_sSectionName; }
103 void SetSectionName(String const& rName){ m_sSectionName = rName; }
104 SectionType GetType() const { return m_eType; }
105 void SetType(SectionType const eNew) { m_eType = eNew; }
107 bool IsHidden() const { return m_bHidden; }
108 void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; }
110 bool IsHiddenFlag() const { return m_bHiddenFlag; }
111 SW_DLLPRIVATE void
112 SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
113 bool IsProtectFlag() const { return m_bProtectFlag; }
114 SW_DLLPRIVATE void
115 SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
116 bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
117 void SetEditInReadonlyFlag(bool const bFlag)
118 { m_bEditInReadonlyFlag = bFlag; }
120 void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; };
121 bool IsCondHidden() const { return m_bCondHiddenFlag; }
123 String const& GetCondition() const { return m_sCondition; }
124 void SetCondition(String const& rNew) { m_sCondition = rNew; }
126 String const& GetLinkFileName() const { return m_sLinkFileName; };
127 void SetLinkFileName(String const& rNew, String const* pPassWd = 0)
129 m_sLinkFileName = rNew;
130 if (pPassWd) { SetLinkFilePassword(*pPassWd); }
133 String const& GetLinkFilePassword() const { return m_sLinkFilePassword; }
134 void SetLinkFilePassword(String const& rS) { m_sLinkFilePassword = rS; }
136 ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
137 { return m_Password; }
138 void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew)
139 { m_Password = rNew; }
140 bool IsLinkType() const
141 { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
143 bool IsConnectFlag() const { return m_bConnectFlag; }
144 void SetConnectFlag(bool const bFlag = true){ m_bConnectFlag = bFlag; }
147 class SW_DLLPUBLIC SwSection
148 : public SwClient
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;
155 private:
156 SwSectionData m_Data;
158 SwServerObjectRef m_RefObj; // Set if DataServer.
159 ::sfx2::SvBaseLinkRef m_RefLink;
161 SW_DLLPRIVATE void ImplSetHiddenFlag(
162 bool const bHidden, bool const bCondition);
164 protected:
165 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
167 public:
168 TYPEINFO(); // rtti
170 SwSection(SectionType const eType, String const& rName,
171 SwSectionFmt & rFormat);
172 virtual ~SwSection();
174 bool DataEquals(SwSectionData const& rCmp) const;
176 void SetSectionData(SwSectionData const& rData);
178 String const& GetSectionName() const { return m_Data.GetSectionName(); }
179 void SetSectionName(String const& rName){ m_Data.SetSectionName(rName); }
180 SectionType GetType() const { return m_Data.GetType(); }
181 void SetType(SectionType const eType) { return m_Data.SetType(eType); }
183 SwSectionFmt* GetFmt() { return (SwSectionFmt*)GetRegisteredIn(); }
184 SwSectionFmt* GetFmt() const { return (SwSectionFmt*)GetRegisteredIn(); }
186 // Set hidden/protected -> update the whole tree!
187 // (Attributes/flags are set/get.)
188 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);
195 // Get internal flags (state including parents, not what is
196 // currently set at section!).
197 bool IsHiddenFlag() const { return m_Data.IsHiddenFlag(); }
198 bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
199 bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
201 void SetCondHidden(bool const bFlag = true);
202 bool IsCondHidden() const { return m_Data.IsCondHidden(); }
203 // Query (also for parents) if this section is to be hidden.
204 sal_Bool CalcHiddenFlag() const;
207 inline SwSection* GetParent() const;
209 String const& GetCondition() const { return m_Data.GetCondition(); }
210 void SetCondition(String const& rNew) { m_Data.SetCondition(rNew); }
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 String const& GetLinkFilePassword() const
216 { return m_Data.GetLinkFilePassword(); }
217 void SetLinkFilePassword(String const& rS)
218 { m_Data.SetLinkFilePassword(rS); }
220 // Get / set password of this section
221 ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
222 { return m_Data.GetPassword(); }
223 void SetPassword(::com::sun::star::uno::Sequence <sal_Int8> const& rNew)
224 { m_Data.SetPassword(rNew); }
226 // Data server methods.
227 void SetRefObject( SwServerObject* pObj );
228 const SwServerObject* GetObject() const { return & m_RefObj; }
229 SwServerObject* GetObject() { return & m_RefObj; }
230 bool IsServer() const { return m_RefObj.Is(); }
232 // Methods for linked ranges.
233 sal_uInt16 GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
234 void SetUpdateType(sal_uInt16 const nType )
235 { m_RefLink->SetUpdateMode(nType); }
237 bool IsConnected() const { return m_RefLink.Is(); }
238 void UpdateNow() { m_RefLink->Update(); }
239 void Disconnect() { m_RefLink->Disconnect(); }
241 const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
242 ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
244 void CreateLink( LinkCreateType eType );
246 void MakeChildLinksVisible( const SwSectionNode& rSectNd );
248 bool IsLinkType() const { return m_Data.IsLinkType(); }
250 // Flags for UI. Did connection work?
251 bool IsConnectFlag() const { return m_Data.IsConnectFlag(); }
252 void SetConnectFlag(bool const bFlag = true)
253 { m_Data.SetConnectFlag(bFlag); }
255 // Return the TOX base class if the section is a TOX section
256 const SwTOXBase* GetTOXBase() const;
258 void BreakLink();
262 // #i117863#
263 class SwSectionFrmMoveAndDeleteHint : public SfxSimpleHint
265 public:
266 SwSectionFrmMoveAndDeleteHint( const sal_Bool bSaveCntnt )
267 : SfxSimpleHint( SFX_HINT_DYING )
268 , mbSaveCntnt( bSaveCntnt )
271 ~SwSectionFrmMoveAndDeleteHint()
274 sal_Bool IsSaveCntnt() const
276 return mbSaveCntnt;
279 private:
280 const sal_Bool mbSaveCntnt;
283 enum SectionSort { SORTSECT_NOT, SORTSECT_NAME, SORTSECT_POS };
285 class SW_DLLPUBLIC SwSectionFmt
286 : public SwFrmFmt
287 , public ::sfx2::Metadatable
289 friend class SwDoc;
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.
295 ::com::sun::star::uno::WeakReference<
296 ::com::sun::star::text::XTextSection> m_wXTextSection;
298 SW_DLLPRIVATE void UpdateParent(); // Parent has been changed.
300 protected:
301 SwSectionFmt( SwSectionFmt* pDrvdFrm, SwDoc *pDoc );
302 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
304 public:
305 TYPEINFO(); // Already contained in base class client.
306 ~SwSectionFmt();
308 // Deletes all Frms in aDepend (Frms are recognized via PTR_CAST).
309 virtual void DelFrms();
311 // Creates views.
312 virtual void MakeFrms();
314 // Get information from Format.
315 virtual bool GetInfo( SfxPoolItem& ) const;
317 SwSection* GetSection() const;
318 inline SwSectionFmt* GetParent() const;
319 inline SwSection* GetParentSection() const;
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;
329 // Query whether section is in Nodes-array or in UndoNodes-array.
330 sal_Bool IsInNodesArr() const;
332 SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false);
333 const SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false) const
334 { return const_cast<SwSectionFmt *>(this)
335 ->GetSectionNode(bEvenIfInUndo); }
337 // Is section a valid one for global document?
338 const SwSection* GetGlobalDocSection() const;
340 SW_DLLPRIVATE ::com::sun::star::uno::WeakReference<
341 ::com::sun::star::text::XTextSection> const& GetXTextSection() const
342 { return m_wXTextSection; }
343 SW_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference<
344 ::com::sun::star::text::XTextSection> const& xTextSection)
345 { m_wXTextSection = xTextSection; }
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();
357 // -------------- inlines ---------------------------------
359 inline SwSection* SwSection::GetParent() const
361 SwSectionFmt* pFmt = GetFmt();
362 SwSection* pRet = 0;
363 if( pFmt )
364 pRet = pFmt->GetParentSection();
365 return pRet;
368 inline SwSectionFmt* SwSectionFmt::GetParent() const
370 SwSectionFmt* pRet = 0;
371 if( GetRegisteredIn() )
372 pRet = PTR_CAST( SwSectionFmt, GetRegisteredIn() );
373 return pRet;
376 inline SwSection* SwSectionFmt::GetParentSection() const
378 SwSectionFmt* pParent = GetParent();
379 SwSection* pRet = 0;
380 if( pParent )
382 pRet = pParent->GetSection();
384 return pRet;
388 #endif /* _SECTION_HXX */
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */