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