xref: /aoo42x/main/sw/inc/section.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SECTION_HXX
29 #define _SECTION_HXX
30 
31 #include <boost/utility.hpp>
32 
33 #include <com/sun/star/uno/Sequence.h>
34 
35 #include <tools/rtti.hxx>
36 #include <tools/ref.hxx>
37 #include <svl/svarray.hxx>
38 #include <sfx2/lnkbase.hxx>
39 #include <sfx2/Metadatable.hxx>
40 
41 #include <frmfmt.hxx>
42 
43 
44 namespace com { namespace sun { namespace star {
45     namespace text { class XTextSection; }
46 } } }
47 
48 // Forward Deklaration
49 class SwSectionFmt;
50 class SwDoc;
51 class SwSection;
52 class SwSectionNode;
53 class SwTOXBase;
54 
55 #ifndef SW_DECL_SWSERVEROBJECT_DEFINED
56 #define SW_DECL_SWSERVEROBJECT_DEFINED
57 SV_DECL_REF( SwServerObject )
58 #endif
59 
60 SV_DECL_PTRARR( SwSections, SwSection*, 0, 4 )
61 
62 enum SectionType { CONTENT_SECTION,
63 					TOX_HEADER_SECTION,
64 					TOX_CONTENT_SECTION,
65 					DDE_LINK_SECTION	= OBJECT_CLIENT_DDE,
66 					FILE_LINK_SECTION	= OBJECT_CLIENT_FILE
67 /*
68 // verbleiben noch:
69 	OBJECT_CLIENT_SO			= 0x80,
70 	OBJECT_CLIENT_OLE			= 0x82,
71 	OBJECT_CLIENT_OLE_CACHE		= 0x83,
72 */
73 					};
74 
75 enum LinkCreateType
76 {
77 	CREATE_NONE,			// nichts weiter tun
78 	CREATE_CONNECT,			// Link gleich connecten
79 	CREATE_UPDATE			// Link connecten und updaten
80 };
81 
82 class SW_DLLPUBLIC SwSectionData
83 {
84 private:
85     SectionType m_eType;
86 
87     String m_sSectionName;
88     String m_sCondition;
89     String m_sLinkFileName;
90     String m_sLinkFilePassword; // JP 27.02.2001: must be changed to Sequence
91     ::com::sun::star::uno::Sequence <sal_Int8> m_Password;
92 
93     /// it seems this flag caches the current final "hidden" state
94     bool m_bHiddenFlag          : 1;
95     /// flags that correspond to attributes in the format:
96     /// may have different value than format attribute:
97     /// format attr has value for this section, while flag is
98     /// effectively ORed with parent sections!
99     bool m_bProtectFlag         : 1;
100     // --> FME 2004-06-22 #114856# edit in readonly sections
101     bool m_bEditInReadonlyFlag  : 1;
102     // <--
103     bool m_bHidden              : 1; // all paragraphs hidden?
104     bool m_bCondHiddenFlag      : 1; // Hiddenflag for condition
105     bool m_bConnectFlag         : 1; // connected to server?
106 
107 public:
108 
109     SwSectionData(SectionType const eType, String const& rName);
110     explicit SwSectionData(SwSection const&);
111     SwSectionData(SwSectionData const&);
112     SwSectionData & operator=(SwSectionData const&);
113     bool operator==(SwSectionData const&) const;
114 
115     String const& GetSectionName() const    { return m_sSectionName; }
116     void SetSectionName(String const& rName){ m_sSectionName = rName; }
117     SectionType GetType() const             { return m_eType; }
118     void SetType(SectionType const eNew)    { m_eType = eNew; }
119 
120     bool IsHidden() const { return m_bHidden; }
121     void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; }
122 
123     bool IsHiddenFlag() const { return m_bHiddenFlag; }
124     SW_DLLPRIVATE void
125         SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
126     bool IsProtectFlag() const { return m_bProtectFlag; }
127     SW_DLLPRIVATE void
128         SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
129     // --> FME 2004-06-22 #114856# edit in readonly sections
130     bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
131     void SetEditInReadonlyFlag(bool const bFlag)
132         { m_bEditInReadonlyFlag = bFlag; }
133     // <--
134 
135     void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; };
136     bool IsCondHidden() const { return m_bCondHiddenFlag; }
137 
138     String const& GetCondition() const      { return m_sCondition; }
139     void SetCondition(String const& rNew)   { m_sCondition = rNew; }
140 
141     String const& GetLinkFileName() const   { return m_sLinkFileName; };
142     void SetLinkFileName(String const& rNew, String const* pPassWd = 0)
143     {
144         m_sLinkFileName = rNew;
145         if (pPassWd) { SetLinkFilePassword(*pPassWd); }
146     }
147 
148     String const& GetLinkFilePassword() const   { return m_sLinkFilePassword; }
149     void SetLinkFilePassword(String const& rS)  { m_sLinkFilePassword = rS; }
150 
151     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
152                                             { return m_Password; }
153     void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew)
154                                             { m_Password = rNew; }
155     bool IsLinkType() const
156     { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); }
157 
158     bool IsConnectFlag() const                  { return m_bConnectFlag; }
159     void SetConnectFlag(bool const bFlag = true){ m_bConnectFlag = bFlag; }
160 };
161 
162 class SW_DLLPUBLIC SwSection
163     : public SwClient
164 {
165 	// damit beim Anlegen/Loeschen von Frames das Flag richtig gepflegt wird!
166 	friend class SwSectionNode;
167 	// the "read CTOR" of SwSectionFrm have to change the Hiddenflag
168 	friend class SwSectionFrm;
169 
170 private:
171     SwSectionData m_Data;
172 
173     SwServerObjectRef m_RefObj; // set if DataServer
174     ::sfx2::SvBaseLinkRef m_RefLink;
175 
176     SW_DLLPRIVATE void ImplSetHiddenFlag(
177             bool const bHidden, bool const bCondition);
178 
179 protected:
180     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
181 
182 public:
183 	TYPEINFO();		// rtti
184 
185     SwSection(SectionType const eType, String const& rName,
186                 SwSectionFmt & rFormat);
187     virtual ~SwSection();
188 
189     bool DataEquals(SwSectionData const& rCmp) const;
190 
191     void SetSectionData(SwSectionData const& rData);
192 
193     String const& GetSectionName() const    { return m_Data.GetSectionName(); }
194     void SetSectionName(String const& rName){ m_Data.SetSectionName(rName); }
195     SectionType GetType() const             { return m_Data.GetType(); }
196     void SetType(SectionType const eType)   { return m_Data.SetType(eType); }
197 
198 	SwSectionFmt* GetFmt() 			{ return (SwSectionFmt*)GetRegisteredIn(); }
199 	SwSectionFmt* GetFmt() const	{ return (SwSectionFmt*)GetRegisteredIn(); }
200 
201 	// setze die Hidden/Protected -> gesamten Baum updaten !
202 	// (Attribute/Flags werden gesetzt/erfragt)
203     bool IsHidden()  const { return m_Data.IsHidden(); }
204     void SetHidden (bool const bFlag = true);
205     bool IsProtect() const;
206     void SetProtect(bool const bFlag = true);
207     // --> FME 2004-06-22 #114856# edit in readonly sections
208     bool IsEditInReadonly() const;
209     void SetEditInReadonly(bool const bFlag = true);
210     // <--
211 
212 	// erfrage die internen Flags (Zustand inklusive Parents nicht, was
213 	// aktuell an der Section gesetzt ist!!)
214     bool IsHiddenFlag()  const { return m_Data.IsHiddenFlag(); }
215     bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
216     // --> FME 2004-06-22 #114856# edit in readonly sections
217     bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
218     // <--
219 
220     void SetCondHidden(bool const bFlag = true);
221     bool IsCondHidden() const { return m_Data.IsCondHidden(); }
222 	// erfrage (auch ueber die Parents), ob diese Section versteckt sein soll.
223 	sal_Bool CalcHiddenFlag() const;
224 
225 
226 	inline SwSection* GetParent() const;
227 
228     String const& GetCondition() const      { return m_Data.GetCondition(); }
229     void SetCondition(String const& rNew)   { m_Data.SetCondition(rNew); }
230 
231 	const String& GetLinkFileName() const;
232     void SetLinkFileName(String const& rNew, String const*const pPassWd = 0);
233     // password of linked file (only valid during runtime!)
234     String const& GetLinkFilePassword() const
235         { return m_Data.GetLinkFilePassword(); }
236     void SetLinkFilePassword(String const& rS)
237         { m_Data.SetLinkFilePassword(rS); }
238 
239 	// get / set password of this section
240     ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const
241                                             { return m_Data.GetPassword(); }
242     void SetPassword(::com::sun::star::uno::Sequence <sal_Int8> const& rNew)
243                                             { m_Data.SetPassword(rNew); }
244 
245 	// Daten Server-Methoden
246 	void SetRefObject( SwServerObject* pObj );
247     const SwServerObject* GetObject() const {  return & m_RefObj; }
248           SwServerObject* GetObject()       {  return & m_RefObj; }
249     bool IsServer() const                   {  return m_RefObj.Is(); }
250 
251 	// Methoden fuer gelinkte Bereiche
252     sal_uInt16 GetUpdateType() const    { return m_RefLink->GetUpdateMode(); }
253     void SetUpdateType(sal_uInt16 const nType )
254         { m_RefLink->SetUpdateMode(nType); }
255 
256     bool IsConnected() const        { return m_RefLink.Is(); }
257     void UpdateNow()                { m_RefLink->Update(); }
258     void Disconnect()               { m_RefLink->Disconnect(); }
259 
260     const ::sfx2::SvBaseLink& GetBaseLink() const    { return *m_RefLink; }
261           ::sfx2::SvBaseLink& GetBaseLink()          { return *m_RefLink; }
262 
263 	void CreateLink( LinkCreateType eType );
264 
265 	void MakeChildLinksVisible( const SwSectionNode& rSectNd );
266 
267     bool IsLinkType() const { return m_Data.IsLinkType(); }
268 
269 	// Flags fuer UI - Verbindung geklappt?
270     bool IsConnectFlag() const      { return m_Data.IsConnectFlag(); }
271     void SetConnectFlag(bool const bFlag = true)
272                                     { m_Data.SetConnectFlag(bFlag); }
273 
274 	// return the TOX base class if the section is a TOX section
275 	const SwTOXBase* GetTOXBase() const;
276 
277     // --> OD 2007-02-14 #b6521322#
278     void BreakLink();
279     // <--
280 
281 };
282 
283 
284 enum SectionSort { SORTSECT_NOT, SORTSECT_NAME, SORTSECT_POS };
285 
286 class SW_DLLPUBLIC SwSectionFmt
287     : public SwFrmFmt
288     , public ::sfx2::Metadatable
289 {
290 	friend class SwDoc;
291 
292     /** why does this exist in addition to the m_wXObject in SwFrmFmt?
293         in case of an index, both a SwXDocumentIndex and a SwXTextSection
294         register at this SwSectionFmt, so we need to have two refs.
295      */
296     ::com::sun::star::uno::WeakReference<
297         ::com::sun::star::text::XTextSection> m_wXTextSection;
298 
299 	SW_DLLPRIVATE void UpdateParent();		// Parent wurde veraendert
300 
301 protected:
302 	SwSectionFmt( SwSectionFmt* pDrvdFrm, SwDoc *pDoc );
303    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
304 
305 public:
306 	TYPEINFO();		//Bereits in Basisklasse Client drin.
307 	~SwSectionFmt();
308 
309 	//Vernichtet alle Frms in aDepend (Frms werden per PTR_CAST erkannt).
310 	virtual void DelFrms();
311 
312 	//Erzeugt die Ansichten
313 	virtual void MakeFrms();
314 
315 		// erfrage vom Format Informationen
316 	virtual sal_Bool GetInfo( SfxPoolItem& ) const;
317 
318     SwSection* GetSection() const;
319 	inline SwSectionFmt* GetParent() const;
320 	inline SwSection* GetParentSection() const;
321 
322 	// alle Sections, die von dieser abgeleitet sind
323 	// 	- sortiert nach : Name oder Position oder unsortiert
324 	//  - alle oder nur die, die sich im normalten Nodes-Array befinden
325 	sal_uInt16 GetChildSections( SwSections& rArr,
326 							SectionSort eSort = SORTSECT_NOT,
327 							sal_Bool bAllSections = sal_True ) const;
328 
329 	// erfrage, ob sich die Section im Nodes-Array oder UndoNodes-Array
330 	// befindet.
331 	sal_Bool IsInNodesArr() const;
332 
333           SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false);
334     const SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false) const
335         { return const_cast<SwSectionFmt *>(this)
336                 ->GetSectionNode(bEvenIfInUndo); }
337 
338 	// ist die Section eine gueltige fuers GlobalDocument?
339 	const SwSection* GetGlobalDocSection() const;
340 
341     SW_DLLPRIVATE ::com::sun::star::uno::WeakReference<
342         ::com::sun::star::text::XTextSection> const& GetXTextSection() const
343             { return m_wXTextSection; }
344     SW_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference<
345                     ::com::sun::star::text::XTextSection> const& xTextSection)
346             { m_wXTextSection = xTextSection; }
347 
348     // sfx2::Metadatable
349     virtual ::sfx2::IXmlIdRegistry& GetRegistry();
350     virtual bool IsInClipboard() const;
351     virtual bool IsInUndo() const;
352     virtual bool IsInContent() const;
353     virtual ::com::sun::star::uno::Reference<
354         ::com::sun::star::rdf::XMetadatable > MakeUnoObject();
355 
356 };
357 
358 // -------------- inlines ---------------------------------
359 
360 inline SwSection* SwSection::GetParent() const
361 {
362 	SwSectionFmt* pFmt = GetFmt();
363 	SwSection* pRet = 0;
364 	if( pFmt )
365 		pRet = pFmt->GetParentSection();
366 	return pRet;
367 }
368 
369 inline SwSectionFmt* SwSectionFmt::GetParent() const
370 {
371 	SwSectionFmt* pRet = 0;
372 	if( GetRegisteredIn() )
373 		pRet = PTR_CAST( SwSectionFmt, GetRegisteredIn() );
374 	return pRet;
375 }
376 
377 inline SwSection* SwSectionFmt::GetParentSection() const
378 {
379 	SwSectionFmt* pParent = GetParent();
380 	SwSection* pRet = 0;
381 	if( pParent )
382     {
383         pRet = pParent->GetSection();
384     }
385 	return pRet;
386 }
387 
388 
389 #endif /* _SECTION_HXX */
390