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 0 : 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 0 : OUString GetSectionName() const { return m_sSectionName; }
100 0 : void SetSectionName(OUString const& rName){ m_sSectionName = rName; }
101 0 : SectionType GetType() const { return m_eType; }
102 0 : void SetType(SectionType const eNew) { m_eType = eNew; }
103 :
104 0 : bool IsHidden() const { return m_bHidden; }
105 0 : void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; }
106 :
107 0 : bool IsHiddenFlag() const { return m_bHiddenFlag; }
108 : SAL_DLLPRIVATE void
109 0 : SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
110 0 : bool IsProtectFlag() const { return m_bProtectFlag; }
111 : SAL_DLLPRIVATE void
112 0 : SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
113 0 : bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
114 0 : void SetEditInReadonlyFlag(bool const bFlag)
115 0 : { m_bEditInReadonlyFlag = bFlag; }
116 :
117 0 : void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; }
118 0 : bool IsCondHidden() const { return m_bCondHiddenFlag; }
119 :
120 0 : OUString GetCondition() const { return m_sCondition; }
121 0 : void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
122 :
123 0 : OUString GetLinkFileName() const { return m_sLinkFileName; }
124 0 : void SetLinkFileName(OUString const& rNew, OUString const* pPassWd = 0)
125 : {
126 0 : m_sLinkFileName = rNew;
127 0 : if (pPassWd) { SetLinkFilePassword(*pPassWd); }
128 0 : }
129 :
130 0 : OUString GetLinkFilePassword() const { return m_sLinkFilePassword; }
131 0 : void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
132 :
133 0 : ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
134 0 : { return m_Password; }
135 0 : void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew)
136 0 : { m_Password = rNew; }
137 0 : bool IsLinkType() const
138 0 : { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
139 :
140 0 : bool IsConnectFlag() const { return m_bConnectFlag; }
141 0 : 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 0 : OUString GetSectionName() const { return m_Data.GetSectionName(); }
178 0 : void SetSectionName(OUString const& rName){ m_Data.SetSectionName(rName); }
179 0 : SectionType GetType() const { return m_Data.GetType(); }
180 0 : void SetType(SectionType const eType) { return m_Data.SetType(eType); }
181 :
182 0 : SwSectionFmt* GetFmt() { return (SwSectionFmt*)GetRegisteredIn(); }
183 0 : SwSectionFmt* GetFmt() const { return (SwSectionFmt*)GetRegisteredIn(); }
184 :
185 : // Set hidden/protected -> update the whole tree!
186 : // (Attributes/flags are set/get.)
187 0 : 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 0 : bool IsHiddenFlag() const { return m_Data.IsHiddenFlag(); }
197 0 : bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
198 0 : bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
199 :
200 : void SetCondHidden(bool const bFlag = true);
201 0 : 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 0 : OUString GetCondition() const { return m_Data.GetCondition(); }
208 0 : 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 0 : OUString GetLinkFilePassword() const
214 0 : { 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 0 : ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
220 0 : { 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 0 : bool IsServer() const { return m_RefObj.Is(); }
229 :
230 : // Methods for linked ranges.
231 0 : sal_uInt16 GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
232 0 : void SetUpdateType(sal_uInt16 const nType )
233 0 : { m_RefLink->SetUpdateMode(nType); }
234 :
235 0 : bool IsConnected() const { return m_RefLink.Is(); }
236 0 : void UpdateNow() { m_RefLink->Update(); }
237 0 : void Disconnect() { m_RefLink->Disconnect(); }
238 :
239 0 : const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
240 0 : ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
241 :
242 : void CreateLink( LinkCreateType eType );
243 :
244 : void MakeChildLinksVisible( const SwSectionNode& rSectNd );
245 :
246 0 : bool IsLinkType() const { return m_Data.IsLinkType(); }
247 :
248 : // Flags for UI. Did connection work?
249 0 : bool IsConnectFlag() const { return m_Data.IsConnectFlag(); }
250 0 : void SetConnectFlag(bool const bFlag = true)
251 0 : { 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 0 : SwSectionFrmMoveAndDeleteHint( const sal_Bool bSaveCntnt )
265 : : SfxSimpleHint( SFX_HINT_DYING )
266 0 : , mbSaveCntnt( bSaveCntnt )
267 0 : {}
268 :
269 0 : virtual ~SwSectionFrmMoveAndDeleteHint()
270 0 : {}
271 :
272 0 : sal_Bool IsSaveCntnt() const
273 : {
274 0 : 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 0 : ::com::sun::star::text::XTextSection> const& GetXTextSection() const
339 0 : { return m_wXTextSection; }
340 0 : SAL_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference<
341 : ::com::sun::star::text::XTextSection> const& xTextSection)
342 0 : { 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 0 : inline SwSection* SwSection::GetParent() const
357 : {
358 0 : SwSectionFmt* pFmt = GetFmt();
359 0 : SwSection* pRet = 0;
360 0 : if( pFmt )
361 0 : pRet = pFmt->GetParentSection();
362 0 : return pRet;
363 : }
364 :
365 0 : inline SwSectionFmt* SwSectionFmt::GetParent() const
366 : {
367 0 : SwSectionFmt* pRet = 0;
368 0 : if( GetRegisteredIn() )
369 0 : pRet = PTR_CAST( SwSectionFmt, GetRegisteredIn() );
370 0 : return pRet;
371 : }
372 :
373 0 : inline SwSection* SwSectionFmt::GetParentSection() const
374 : {
375 0 : SwSectionFmt* pParent = GetParent();
376 0 : SwSection* pRet = 0;
377 0 : if( pParent )
378 : {
379 0 : pRet = pParent->GetSection();
380 : }
381 0 : return pRet;
382 : }
383 :
384 : #endif /* _ INCLUDED_SW_INC_SECTION_HXX */
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|