1 /* AbiWord
2  * Copyright (C) 2004 Martin Sevior <msevior@physics.unimelb.edu.au>
3  * Copyright (C) 1998 AbiSource, Inc.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301 USA.
19  */
20 
21 #ifndef TOCLAYOUT_H
22 #define TOCLAYOUT_H
23 
24 #include "ut_string_class.h"
25 #include "ut_types.h"
26 #include "ut_vector.h"
27 #include "pt_Types.h"
28 #include "fl_Layout.h"
29 #include "fl_DocLayout.h"
30 #include "fl_BlockLayout.h"
31 #include "fl_ContainerLayout.h"
32 #include "fl_SectionLayout.h"
33 #include "pl_Listener.h"
34 #include "ut_debugmsg.h"
35 
36 class PD_Style;
37 class fp_TOCContainer;
38 
39 class ABI_EXPORT TOCEntry
40 {
41 public:
42 	TOCEntry(fl_BlockLayout * pBlock,
43 			 UT_sint32 iLevel,
44 			 UT_UTF8String & sDispStyle,
45 			 bool bHaveLabel,
46 			 FootnoteType iFType,
47 			 UT_UTF8String & sBefore,
48 			 UT_UTF8String sAfter,
49 			 bool bInherit,
50 			 UT_sint32 iStartAt);
51 
52 	virtual ~ TOCEntry(void);
getBlock(void)53 	fl_BlockLayout *     getBlock(void)
54 		{ return m_pBlock;}
55 	PT_DocPosition       getPositionInDoc(void);
getLevel(void)56 	UT_sint32            getLevel(void)
57 		{ return m_iLevel;}
getDispStyle(void)58 	UT_UTF8String &      getDispStyle(void)
59 		{ return m_sDispStyle;}
hasLabel(void)60 	bool                 hasLabel(void) const
61 		{ return m_bHasLabel;}
doesInherit(void)62 	bool                 doesInherit(void)
63 		{ return m_bInherit;}
64 	void                 setPosInList(UT_sint32 posInList);
getPosInList(void)65 	UT_sint32            getPosInList(void)
66 		{ return m_iPosInList;}
67 	void                 calculateLabel(TOCEntry * pPrevLevel);
getNumLabel(void)68     UT_UTF8String &      getNumLabel(void)
69 		{ return m_sLabel;}
70 	UT_UTF8String       getFullLabel(void);
71 private:
72 	fl_BlockLayout *  m_pBlock;
73 	UT_sint32         m_iLevel;
74 	UT_UTF8String     m_sDispStyle;
75 	bool              m_bHasLabel;
76 	FootnoteType      m_iFType;
77 	UT_UTF8String     m_sBefore;
78 	UT_UTF8String     m_sAfter;
79 	bool              m_bInherit;
80 	UT_sint32         m_iPosInList;
81 	UT_UTF8String     m_sLabel;
82 	UT_sint32         m_iStartAt;
83 };
84 
85 // We have one fl_TOCLayout for each Table of Contents.
86 
87 class ABI_EXPORT fl_TOCLayout : public fl_SectionLayout
88 {
89 	friend class fl_DocListener;
90 	friend class fp_FootnoteContainer;
91 
92 public:
93 	fl_TOCLayout(FL_DocLayout* pLayout,
94 				 fl_DocSectionLayout * pDocSL,
95 				 pf_Frag_Strux* sdh,
96 				 PT_AttrPropIndex ap,
97 				 fl_ContainerLayout * pMyContainerLayout);
98 
99 	virtual ~fl_TOCLayout();
100 
101 	virtual bool 	doclistener_changeStrux(const PX_ChangeRecord_StruxChange * pcrxc);
102 	virtual bool    doclistener_deleteStrux(const PX_ChangeRecord_Strux * pcrx);
103 	virtual bool    doclistener_deleteEndTOC(const PX_ChangeRecord_Strux * pcrx);
104 	virtual bool    bl_doclistener_insertEndTOC(fl_ContainerLayout*,
105 												const PX_ChangeRecord_Strux * pcrx,
106 												pf_Frag_Strux* sdh,
107 												PL_ListenerId lid,
108 												void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
109 																		PL_ListenerId lid,
110 																		fl_ContainerLayout* sfhNew));
111 
112 	virtual void		     format(void);
113 	virtual void		     updateLayout(bool bDoFull);
114 	virtual void             collapse(void);
115 	virtual void             markAllRunsDirty(void);
116 	virtual fl_SectionLayout *  getSectionLayout(void)  const;
117 	bool                     recalculateFields(UT_uint32 iUpdateCount);
118 	virtual void		     redrawUpdate(void);
119 	virtual fp_Container*	 getNewContainer(fp_Container* = NULL);
getDocSectionLayout(void)120 	fl_DocSectionLayout*	 getDocSectionLayout(void) const { return m_pDocSL; }
isEndTOCIn(void)121 	bool                     isEndTOCIn(void) const {return m_bHasEndTOC;}
122 	void                     setTOCEndIn(void);
123 	TOCEntry *               createNewEntry(fl_BlockLayout * pBL);
124 	PT_DocPosition           getDocPosition(void);
125 	UT_uint32                getLength(void);
126     fl_BlockLayout  *        findMatchingBlock(fl_BlockLayout * pBlock);
127 	UT_sint32                isInVector(fl_BlockLayout * pBlock, UT_GenericVector<TOCEntry *>* pVecBlocks);
getTOCPID(void)128 	UT_uint32                getTOCPID(void) const { return m_iTOCPID;}
isTOCEmpty()129 	bool                     isTOCEmpty() const {return (m_vecEntries.getItemCount() == 0);}
130 	bool                     isStyleInTOC(UT_UTF8String & sStyle);
131 	bool                     isBlockInTOC(fl_BlockLayout * pBlock);
132 	bool                     addBlock(fl_BlockLayout * pBlock, bool bVerifyRange = true);
133 	bool                     removeBlock(fl_BlockLayout * pBlock);
134 	fl_BlockLayout *         getMatchingBlock(fl_BlockLayout * pBlock);
135 	UT_UTF8String &          getTOCListLabel(fl_BlockLayout * pBlock);
getTOCHeading(void)136 	UT_UTF8String &          getTOCHeading(void) { return m_sTOCHeading;}
getCurrentLevel(void)137 	UT_sint32                getCurrentLevel(void) const { return m_iCurrentLevel;}
138 	FootnoteType             getNumType(UT_sint32 iLevel);
139 	eTabLeader               getTabLeader(UT_sint32 iLevel);
140 	UT_sint32                getTabPosition(UT_sint32 iLevel, const fl_BlockLayout * pBlock);
141 	void                     setSelected(bool bSetSelected);
isSelected(void)142 	bool                     isSelected(void) { return m_bIsSelected;}
143 
getRangeBookmarkName()144 	const UT_UTF8String &    getRangeBookmarkName() const {return m_sRangeBookmark;}
145 	bool                     verifyBookmarkAssumptions();
146 	bool                     fillTOC(void);
147 
148 	static std::string       getDefaultHeading();
149 	static UT_UTF8String     getDefaultSourceStyle(UT_uint32 iLevel);
150 	static UT_UTF8String     getDefaultDestStyle(UT_uint32 iLevel);
151 
152 private:
153 	virtual void             _purgeLayout(void);
154 	virtual void		     _lookupProperties(const PP_AttrProp* pAP);
155 	void                     _createTOCContainer(void);
156 	bool                     _isStyleInTOC(UT_UTF8String & sStyle, UT_UTF8String & sTOCStyle);
157 	void                     _insertTOCContainer(fp_TOCContainer * pNewTOC);
158 	void                     _localCollapse();
159 
160 	void                     _createAndFillTOCEntry(PT_DocPosition posStart, PT_DocPosition posEnd,
161 													fl_BlockLayout * pPrevBL, const char * pszStyle,
162 													UT_sint32 iAllBlocks);
163 
164 	void                     _addBlockInVec(fl_BlockLayout * pBlock,UT_UTF8String & sStyle);
165 	void                     _removeBlockInVec(fl_BlockLayout * pBlock, bool bDontRecurse = false);
166 	void                     _calculateLabels(void);
167 	UT_sint32                _getStartValue(TOCEntry * pEntry);
168 	bool                     m_bNeedsRebuild;
169 	bool                     m_bNeedsFormat;
170 	bool                     m_bIsOnPage;
171 	UT_uint32                m_iTOCPID;
172 	fl_DocSectionLayout*	 m_pDocSL;
173 	bool                     m_bHasEndTOC;
174 	bool                     m_bDoingPurge;
175 	bool                     m_bIsSelected;
176 	UT_UTF8String            m_sSourceStyle1;
177 	UT_UTF8String            m_sSourceStyle2;
178 	UT_UTF8String            m_sSourceStyle3;
179 	UT_UTF8String            m_sSourceStyle4;
180 	UT_UTF8String            m_sDestStyle1;
181 	UT_UTF8String            m_sDestStyle2;
182 	UT_UTF8String            m_sDestStyle3;
183 	UT_UTF8String            m_sDestStyle4;
184 	UT_UTF8String            m_sNumOff1;
185 	UT_UTF8String            m_sNumOff2;
186 	UT_UTF8String            m_sNumOff3;
187 	UT_UTF8String            m_sNumOff4;
188 	FootnoteType             m_iNumType1;
189 	FootnoteType             m_iNumType2;
190 	FootnoteType             m_iNumType3;
191 	FootnoteType             m_iNumType4;
192 	eTabLeader               m_iTabLeader1;
193 	eTabLeader               m_iTabLeader2;
194 	eTabLeader               m_iTabLeader3;
195 	eTabLeader               m_iTabLeader4;
196 	UT_GenericVector<TOCEntry *> m_vecEntries;
197 	UT_sint32                m_iCurrentLevel;
198 	UT_UTF8String            m_sTOCHeading;
199 	bool                     m_bTOCHeading;
200 	UT_UTF8String            m_sTOCHeadingStyle;
201 	FootnoteType             m_iLabType1;
202 	FootnoteType             m_iLabType2;
203 	FootnoteType             m_iLabType3;
204 	FootnoteType             m_iLabType4;
205 	UT_UTF8String            m_sLabBefore1;
206 	UT_UTF8String            m_sLabBefore2;
207 	UT_UTF8String            m_sLabBefore3;
208 	UT_UTF8String            m_sLabBefore4;
209 	UT_UTF8String            m_sLabAfter1;
210 	UT_UTF8String            m_sLabAfter2;
211 	UT_UTF8String            m_sLabAfter3;
212 	UT_UTF8String            m_sLabAfter4;
213 	UT_UTF8String            m_sRangeBookmark;
214 	bool                     m_bHasLabel1;
215 	bool                     m_bHasLabel2;
216 	bool                     m_bHasLabel3;
217 	bool                     m_bHasLabel4;
218 	bool                     m_bInherit1;
219 	bool                     m_bInherit2;
220 	bool                     m_bInherit3;
221 	bool                     m_bInherit4;
222 	UT_sint32                m_iStartAt1;
223 	UT_sint32                m_iStartAt2;
224 	UT_sint32                m_iStartAt3;
225 	UT_sint32                m_iStartAt4;
226 	bool                     m_bMissingBookmark;
227 	bool                     m_bFalseBookmarkEstimate;
228 	UT_NumberVector          m_vecBookmarkPositions;
229 };
230 
231 
232 class ABI_EXPORT fl_TOCListener : public PL_Listener
233 {
234 public:
235 	fl_TOCListener(fl_TOCLayout* pTOCL, fl_BlockLayout * pPrevBL, PD_Style * pStyle);
236 	virtual ~fl_TOCListener();
237 
238 	virtual bool				populate(fl_ContainerLayout* sfh,
239 										 const PX_ChangeRecord * pcr);
240 
241 	virtual bool				populateStrux(pf_Frag_Strux* sdh,
242 											  const PX_ChangeRecord * pcr,
243 											  fl_ContainerLayout* * psfh);
244 
245 	virtual bool				change(fl_ContainerLayout* sfh,
246 									   const PX_ChangeRecord * pcr);
247 
248 	virtual bool				insertStrux(fl_ContainerLayout* sfh,
249 											const PX_ChangeRecord * pcr,
250 											pf_Frag_Strux* sdh,
251 											PL_ListenerId lid,
252 											void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
253 																	PL_ListenerId lid,
254 																	fl_ContainerLayout* sfhNew));
255 
256 	virtual bool				signal(UT_uint32 iSignal);
257 
258 private:
259 	PD_Document*				m_pDoc;
260 	fl_TOCLayout* 			    m_pTOCL;
261 	fl_BlockLayout *            m_pPrevBL;
262 	bool						m_bListening;
263 	fl_ContainerLayout*			m_pCurrentBL;
264 	PD_Style *                  m_pStyle;
265 };
266 
267 #endif /* TOCLAYOUT_H */
268