1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SW_INC_SECTION_HXX
#define INCLUDED_SW_INC_SECTION_HXX
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/text/XTextSection.hpp>
#include <tools/ref.hxx>
#include <svl/hint.hxx>
#include <svl/listener.hxx>
#include <sfx2/lnkbase.hxx>
#include <sfx2/Metadatable.hxx>
#include "frmfmt.hxx"
#include <vector>
class SwSectionFormat;
class SwDoc;
class SwSection;
class SwSectionNode;
class SwTOXBase;
class SwServerObject;
typedef std::vector<SwSection*> SwSections;
enum class SectionType { Content,
ToxHeader,
ToxContent,
DdeLink = static_cast<int>(sfx2::SvBaseLinkObjectType::ClientDde),
FileLink = static_cast<int>(sfx2::SvBaseLinkObjectType::ClientFile)
};
enum class LinkCreateType
{
NONE, // Do nothing.
Connect, // Connect created link.
Update // Connect created link and update it.
};
class SW_DLLPUBLIC SwSectionData
{
private:
SectionType m_eType;
OUString m_sSectionName;
OUString m_sCondition; ///< Hide condition
OUString m_sLinkFileName;
OUString m_sLinkFilePassword; // Must be changed to Sequence.
css::uno::Sequence <sal_Int8> m_Password;
/// It seems this flag caches the current final "hidden" state.
bool m_bHiddenFlag : 1;
/// Flags that correspond to attributes in the format:
/// may have different value than format attribute:
/// format attr has value for this section, while flag is
/// effectively ORed with parent sections!
bool m_bProtectFlag : 1; ///< protect flag is no longer inherited
// Edit in readonly sections.
bool m_bEditInReadonlyFlag : 1;
bool m_bHidden : 1; ///< Section is hidden, unless condition evaluates `false'
bool m_bCondHiddenFlag : 1; ///< Hide condition evaluated `true'
bool m_bConnectFlag : 1; // Connected to server?
public:
SwSectionData(SectionType const eType, OUString const& rName);
explicit SwSectionData(SwSection const&);
SwSectionData(SwSectionData const&);
SwSectionData & operator=(SwSectionData const&);
bool operator==(SwSectionData const&) const;
const OUString& GetSectionName() const { return m_sSectionName; }
void SetSectionName(OUString const& rName){ m_sSectionName = rName; }
SectionType GetType() const { return m_eType; }
void SetType(SectionType const eNew) { m_eType = eNew; }
bool IsHidden() const { return m_bHidden; }
void SetHidden(bool const bFlag) { m_bHidden = bFlag; }
bool IsHiddenFlag() const { return m_bHiddenFlag; }
SAL_DLLPRIVATE void
SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
bool IsProtectFlag() const { return m_bProtectFlag; }
SAL_DLLPRIVATE void
SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
void SetEditInReadonlyFlag(bool const bFlag)
{ m_bEditInReadonlyFlag = bFlag; }
void SetCondHidden(bool const bFlag) { m_bCondHiddenFlag = bFlag; }
bool IsCondHidden() const { return m_bCondHiddenFlag; }
const OUString& GetCondition() const { return m_sCondition; }
void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
const OUString& GetLinkFileName() const { return m_sLinkFileName; }
void SetLinkFileName(OUString const& rNew)
{
m_sLinkFileName = rNew;
}
const OUString& GetLinkFilePassword() const { return m_sLinkFilePassword; }
void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
css::uno::Sequence<sal_Int8> const& GetPassword() const
{ return m_Password; }
void SetPassword(css::uno::Sequence<sal_Int8> const& rNew)
{ m_Password = rNew; }
bool IsLinkType() const
{ return (SectionType::DdeLink == m_eType) || (SectionType::FileLink == m_eType); }
bool IsConnectFlag() const { return m_bConnectFlag; }
void SetConnectFlag(bool const bFlag){ m_bConnectFlag = bFlag; }
};
class SW_DLLPUBLIC SwSection
: public SwClient
, public SvtListener // needed for SwClientNotify to be called from SwSectionFormat
{
// In order to correctly maintain the flag when creating/deleting frames.
friend class SwSectionNode;
// The "read CTOR" of SwSectionFrame have to change the Hiddenflag.
friend class SwSectionFrame;
private:
mutable SwSectionData m_Data;
tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
tools::SvRef<sfx2::SvBaseLink> m_RefLink;
SAL_DLLPRIVATE void ImplSetHiddenFlag(
bool const bHidden, bool const bCondition);
protected:
virtual void Notify(SfxHint const& rHint) override;
virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
public:
SwSection(SectionType const eType, OUString const& rName,
SwSectionFormat & rFormat);
virtual ~SwSection() override;
bool DataEquals(SwSectionData const& rCmp) const;
void SetSectionData(SwSectionData const& rData);
const OUString& GetSectionName() const { return m_Data.GetSectionName(); }
void SetSectionName(OUString const& rName){ m_Data.SetSectionName(rName); }
SectionType GetType() const { return m_Data.GetType(); }
void SetType(SectionType const eType) { return m_Data.SetType(eType); }
inline SwSectionFormat* GetFormat();
inline SwSectionFormat const * GetFormat() const;
// Set hidden/protected -> update the whole tree!
// (Attributes/flags are set/get.)
bool IsHidden() const { return m_Data.IsHidden(); }
void SetHidden (bool const bFlag = true);
bool IsProtect() const;
void SetProtect(bool const bFlag = true);
bool IsEditInReadonly() const;
void SetEditInReadonly(bool const bFlag = true);
// Get internal flags (state including parents, not what is
// currently set at section!).
bool IsHiddenFlag() const { return m_Data.IsHiddenFlag(); }
bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
void SetCondHidden(bool const bFlag);
bool IsCondHidden() const { return m_Data.IsCondHidden(); }
// Query (also for parents) if this section is to be hidden.
bool CalcHiddenFlag() const;
inline SwSection* GetParent() const;
OUString const & GetCondition() const { return m_Data.GetCondition(); }
void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
OUString const & GetLinkFileName() const;
void SetLinkFileName(OUString const& rNew);
// Password of linked file (only valid during runtime!)
OUString const & GetLinkFilePassword() const
{ return m_Data.GetLinkFilePassword(); }
void SetLinkFilePassword(OUString const& rS)
{ m_Data.SetLinkFilePassword(rS); }
// Get / set password of this section
css::uno::Sequence<sal_Int8> const& GetPassword() const
{ return m_Data.GetPassword(); }
// Data server methods.
void SetRefObject( SwServerObject* pObj );
const SwServerObject* GetObject() const { return m_RefObj.get(); }
SwServerObject* GetObject() { return m_RefObj.get(); }
bool IsServer() const { return m_RefObj.is(); }
// Methods for linked ranges.
SfxLinkUpdateMode GetUpdateType() const { return m_RefLink->GetUpdateMode(); }
void SetUpdateType(SfxLinkUpdateMode nType )
{ m_RefLink->SetUpdateMode(nType); }
bool IsConnected() const { return m_RefLink.is(); }
void UpdateNow() { m_RefLink->Update(); }
void Disconnect() { m_RefLink->Disconnect(); }
const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; }
::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; }
void CreateLink( LinkCreateType eType );
static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
bool IsLinkType() const { return m_Data.IsLinkType(); }
// Flags for UI. Did connection work?
bool IsConnectFlag() const { return m_Data.IsConnectFlag(); }
void SetConnectFlag(bool const bFlag = true)
{ m_Data.SetConnectFlag(bFlag); }
// Return the TOX base class if the section is a TOX section
const SwTOXBase* GetTOXBase() const;
void BreakLink();
void dumpAsXml(xmlTextWriterPtr pWriter) const;
};
// #i117863#
class SwSectionFrameMoveAndDeleteHint final : public SfxHint
{
public:
SwSectionFrameMoveAndDeleteHint( const bool bSaveContent )
: SfxHint( SfxHintId::SwSectionFrameMoveAndDelete )
, mbSaveContent( bSaveContent )
{}
bool IsSaveContent() const
{
return mbSaveContent;
}
private:
const bool mbSaveContent;
};
enum class SectionSort { Not, Pos };
class SW_DLLPUBLIC SwSectionFormat final
: public SwFrameFormat
, public ::sfx2::Metadatable
{
friend class SwDoc;
/** Why does this exist in addition to the m_wXObject in SwFrameFormat?
in case of an index, both a SwXDocumentIndex and a SwXTextSection
register at this SwSectionFormat, so we need to have two refs.
*/
css::uno::WeakReference<css::text::XTextSection> m_wXTextSection;
SAL_DLLPRIVATE void UpdateParent(); // Parent has been changed.
SwSectionFormat( SwFrameFormat* pDrvdFrame, SwDoc *pDoc );
virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
public:
virtual ~SwSectionFormat() override;
// Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
virtual void DelFrames() override;
// Creates views.
virtual void MakeFrames() override;
// Get information from Format.
virtual bool GetInfo( SfxPoolItem& ) const override;
SwSection* GetSection() const;
inline SwSectionFormat* GetParent() const;
inline SwSection* GetParentSection() const;
// All sections that are derived from this one:
// - sorted according to name or position or unsorted
// - all of them or only those that are in the normal Nodes-array.
void GetChildSections( SwSections& rArr,
SectionSort eSort = SectionSort::Not,
bool bAllSections = true ) const;
// Query whether section is in Nodes-array or in UndoNodes-array.
bool IsInNodesArr() const;
SwSectionNode* GetSectionNode();
const SwSectionNode* GetSectionNode() const
{ return const_cast<SwSectionFormat *>(this)
->GetSectionNode(); }
// Is section a valid one for global document?
const SwSection* GetGlobalDocSection() const;
SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextSection> const& GetXTextSection() const
{ return m_wXTextSection; }
SAL_DLLPRIVATE void SetXTextSection(css::uno::Reference<css::text::XTextSection> const& xTextSection)
{ m_wXTextSection = xTextSection; }
// sfx2::Metadatable
virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
virtual bool IsInClipboard() const override;
virtual bool IsInUndo() const override;
virtual bool IsInContent() const override;
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
virtual bool supportsFullDrawingLayerFillAttributeSet() const override;
void dumpAsXml(xmlTextWriterPtr pWriter) const;
};
SwSectionFormat* SwSection::GetFormat()
{
return static_cast<SwSectionFormat*>(GetRegisteredIn());
}
SwSectionFormat const * SwSection::GetFormat() const
{
return static_cast<SwSectionFormat const *>(GetRegisteredIn());
}
inline SwSection* SwSection::GetParent() const
{
SwSectionFormat const * pFormat = GetFormat();
SwSection* pRet = nullptr;
if( pFormat )
pRet = pFormat->GetParentSection();
return pRet;
}
inline SwSectionFormat* SwSectionFormat::GetParent() const
{
SwSectionFormat* pRet = nullptr;
if( GetRegisteredIn() )
pRet = const_cast<SwSectionFormat*>(dynamic_cast< const SwSectionFormat* >( GetRegisteredIn() ));
return pRet;
}
inline SwSection* SwSectionFormat::GetParentSection() const
{
SwSectionFormat* pParent = GetParent();
SwSection* pRet = nullptr;
if( pParent )
{
pRet = pParent->GetSection();
}
return pRet;
}
#endif /* _ INCLUDED_SW_INC_SECTION_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|