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