1 /* AbiWord
2  * Copyright (C) 1998 AbiSource, Inc.
3  * Copyright (C) 2002 Martin Sevior <msevior@physics.unimelb.edu.au>
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 TABLELAYOUT_H
22 #define TABLELAYOUT_H
23 
24 #ifdef FMT_TEST
25 #include <stdio.h>
26 #endif
27 
28 #include "ut_types.h"
29 #include "ut_vector.h"
30 #include "pt_Types.h"
31 #include "fl_Layout.h"
32 #include "fl_ContainerLayout.h"
33 #include "fl_SectionLayout.h"
34 #include "pp_PropertyMap.h"
35 #include "pl_Listener.h"
36 #include "ut_debugmsg.h"
37 #include "ut_misc.h" // for UT_RGBColor
38 
39 enum  FL_TableJustification
40 {
41     FL_TABLE_LEFT,
42     FL_TABLE_CENTER,
43     FL_TABLE_RIGHT,
44     FL_TABLE_FULL
45 };
46 
47 enum FL_RowHeightType
48 {
49 	FL_ROW_HEIGHT_NOT_DEFINED,
50 	FL_ROW_HEIGHT_AUTO,
51 	FL_ROW_HEIGHT_AT_LEAST,
52 	FL_ROW_HEIGHT_EXACTLY
53 };
54 
55 class fp_Page;
56 class FL_DocLayout;
57 class fl_Layout;
58 class fl_ContainerLayout;
59 class fl_BlockLayout;
60 class fl_SectionLayout;
61 class fl_DocSectionLayout;
62 class fl_HdrFtrSectionLayout;
63 class fl_HdrFtrShadow;
64 class fl_CellLayout;
65 class fb_LineBreaker;
66 class fp_ShadowContainer;
67 class fp_Column;
68 class fp_Run;
69 class fp_Line;
70 class fp_Container;
71 class fp_HdrFtrContainer;
72 class fp_TableContainer;
73 class fp_CellContainer;
74 class PD_Document;
75 class PP_AttrProp;
76 class PX_ChangeRecord_FmtMark;
77 class PX_ChangeRecord_FmtMarkChange;
78 class PX_ChangeRecord_Object;
79 class PX_ChangeRecord_ObjectChange;
80 class PX_ChangeRecord_Span;
81 class PX_ChangeRecord_SpanChange;
82 class PX_ChangeRecord_Strux;
83 class PX_ChangeRecord_StruxChange;
84 class pf_Frag_Strux;
85 
86 class ABI_EXPORT fl_ColProps
87 {
88 public:
89 	UT_sint32 m_iColWidth;
90 	double    m_dColRelWidth;
91 };
92 
93 class ABI_EXPORT fl_RowProps
94 {
95 public:
fl_RowProps(void)96 	fl_RowProps(void)
97 	{
98 		m_iRowHeight = 0;
99 		m_iRowHeightType = FL_ROW_HEIGHT_NOT_DEFINED;
100 	}
~fl_RowProps(void)101 	virtual ~fl_RowProps(void)
102 	{
103 	}
104 	UT_sint32          m_iRowHeight;
105 	FL_RowHeightType   m_iRowHeightType;
106 };
107 
108 
109 class ABI_EXPORT fl_TableLayout : public fl_SectionLayout
110 {
111 	friend class fl_DocListener;
112 
113 public:
114 	fl_TableLayout(FL_DocLayout* pLayout, pf_Frag_Strux* sdh, PT_AttrPropIndex ap, fl_ContainerLayout * pMyContainerLayout);
115 	virtual ~fl_TableLayout();
116 
getType(void)117 	SectionType     	        getType(void) const { return m_iType; }
118 
119 	virtual bool		        recalculateFields(UT_uint32 iUpdateCount);
120 	virtual bool 	            doclistener_changeStrux(const PX_ChangeRecord_StruxChange * pcrxc);
121 	virtual bool				doclistener_deleteStrux(const PX_ChangeRecord_Strux * pcrx);
122 	virtual bool                bl_doclistener_insertCell(fl_ContainerLayout* pCell,
123 											  const PX_ChangeRecord_Strux * pcrx,
124 											  pf_Frag_Strux* sdh,
125 											  PL_ListenerId lid,
126 											  void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
127 																	  PL_ListenerId lid,
128 																	  fl_ContainerLayout* sfhNew));
129 	virtual bool                bl_doclistener_insertBlock(fl_ContainerLayout* pCell,
130 											  const PX_ChangeRecord_Strux * pcrx,
131 											  pf_Frag_Strux* sdh,
132 											  PL_ListenerId lid,
133 											  void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
134 																	  PL_ListenerId lid,
135 																	  fl_ContainerLayout* sfhNew));
136 
137 	virtual bool                bl_doclistener_insertEndTable(fl_ContainerLayout*,
138 											  const PX_ChangeRecord_Strux * pcrx,
139 											  pf_Frag_Strux* sdh,
140 											  PL_ListenerId lid,
141 											  void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
142 																	  PL_ListenerId lid,
143 																	  fl_ContainerLayout* sfhNew));
144 
145 	virtual bool               bl_doclistener_insertTable( const PX_ChangeRecord_Strux * pcrx,
146 											   SectionType iType,
147 											   pf_Frag_Strux* sdh,
148 											   PL_ListenerId lid,
149 											   void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
150 																	   PL_ListenerId lid,
151 																	   fl_ContainerLayout* sfhNew));
152 
153 #ifdef FMT_TEST
154 	virtual void		__dump(FILE * fp) const;
155 #endif
156 	void                        setTableContainerProperties(fp_TableContainer * pTab);
157 	virtual void		        format(void);
158 	void                        attachCell(fl_ContainerLayout * pCell);
159 	void                        createTableContainer(void);
160 	void                        insertTableContainer(fp_TableContainer * pNewTab);
161 	virtual void		        updateLayout(bool bDoFull);
162 	void		                updateTable(void);
163 	virtual void                collapse(void);
164 	virtual void                markAllRunsDirty(void);
165 	virtual bool                needsReformat(void) const;
166 	virtual PT_DocPosition      getPosition(bool bActualBlockPosition = false) const;
167 	UT_uint32                   getLength(void);
168 	virtual void		        redrawUpdate(void);
169 	virtual fp_Container*		getNewContainer(fp_Container * pFirstContainer = NULL);
170 	virtual fl_SectionLayout *  getSectionLayout(void)  const;
171 
markForRebuild(void)172 	void                        markForRebuild(void) { m_bNeedsRebuild = true;}
clearRebuild(void)173 	void                        clearRebuild(void) { m_bNeedsRebuild = false;}
needsRebuild(void)174 	bool                        needsRebuild(void) const { return m_bNeedsRebuild;}
markForReformat(void)175     void                        markForReformat(void) { m_bNeedsReformat = true;}
needsReFormat(void)176     bool                        needsReFormat(void) const { return m_bNeedsReformat;}
177 
178 	UT_sint32                getLeftOffset(void) const;
179 	void                     setHeightChanged(fp_CellContainer * pCell);
180     bool                     doSimpleChange(void);
181 UT_sint32                    getRightOffset(void) const;
182 	UT_sint32                getTopOffset(void) const;
183 UT_sint32                    getBottomOffset(void) const;
isDirty(void)184 	bool                     isDirty(void) const
185 		{ return m_bIsDirty;}
186 	void                     setDirty(void);
getTableRelWidth(void)187 	double                   getTableRelWidth(void) const
188 	{ return m_dTableRelWidth;}
189 	UT_sint32                getLineThickness(void) const;
190 	UT_sint32                getColSpacing(void) const;
191 	UT_sint32                getRowSpacing(void) const;
getLeftColPos(void)192 	UT_sint32                getLeftColPos(void) const
193 		{ return m_iLeftColPos;}
getVecColProps(void)194 	const UT_GenericVector<fl_ColProps*> * getVecColProps(void) const
195 		{ return &m_vecColProps;}
getVecRowProps(void)196 	const UT_GenericVector<fl_RowProps*> * getVecRowProps(void) const
197 		{ return &m_vecRowProps;}
198 
getBackground()199 	const PP_PropertyMap::Background & getBackground () const { return m_background; }
200 
getDefaultColor()201 	const UT_RGBColor & getDefaultColor () const { return m_colorDefault; }
202 
getBottomStyle()203 	const PP_PropertyMap::Line & getBottomStyle () const { return m_lineBottom; }
getLeftStyle()204 	const PP_PropertyMap::Line & getLeftStyle ()   const { return m_lineLeft; }
getRightStyle()205 	const PP_PropertyMap::Line & getRightStyle ()  const { return m_lineRight; }
getTopStyle()206 	const PP_PropertyMap::Line & getTopStyle ()    const { return m_lineTop; }
207 	UT_sint32                getNumNestedTables(void) const;
208 	void                     incNumNestedTables(void);
209 	void                     decNumNestedTables(void);
210 
setEndTableIn(void)211 	void                     setEndTableIn(void)
212 		{ m_bIsEndTableIn = true;}
isEndTableIn(void)213 	bool                     isEndTableIn(void) const
214 	  { return m_bIsEndTableIn;}
isDoingDestructor(void)215 	bool                     isDoingDestructor(void) const
216 	{ return m_bDoingDestructor;}
isInitialLayoutCompleted(void)217 	bool                     isInitialLayoutCompleted(void) const
218 	{ return m_bInitialLayoutCompleted;}
getMaxExtraMargin(void)219 	double                   getMaxExtraMargin(void) const
220 	{ return m_dMaxExtraMargin;}
221 	void                     setMaxExtraMargin(double margin);
222 
223 protected:
224 	virtual void		        _lookupProperties(const PP_AttrProp* pSectionAP);
225 	virtual void			    _lookupMarginProperties(const PP_AttrProp* pAP);
226 	void				        _purgeLayout();
227 private:
228 	bool                   m_bNeedsRebuild;
229 	FL_TableJustification  m_iJustification;
230 	UT_sint32              m_iLeftOffset;
231 	double                 m_dLeftOffsetUserUnits;
232 	UT_sint32              m_iRightOffset;
233 	double                 m_dRightOffsetUserUnits;
234 	UT_sint32              m_iTopOffset;
235 	double                 m_dTopOffsetUserUnits;
236 	UT_sint32              m_iBottomOffset;
237 	double                 m_dBottomOffsetUserUnits;
238 
239 	bool                   m_bIsHomogeneous;
240 	bool                   m_bSameRowOnTopOfPage;
241 	UT_sint32              m_iRowNumberForTop;
242 	UT_sint32              m_iNumberOfRows;
243 	UT_sint32              m_iNumberOfColumns;
244 	bool                   m_bColumnsPositionedOnPage;
245 	bool                   m_bRowsPositionedOnPage;
246 	bool                   m_bIsDirty;
247 	bool                   m_bDontImmediatelyLayout;
248 	bool                   m_bInitialLayoutCompleted;
249 	UT_sint32              m_iLineThickness;
250 	UT_sint32              m_iColSpacing;
251 	UT_sint32              m_iRowSpacing;
252 	UT_sint32              m_iLeftColPos;
253 	bool                   m_bRecursiveFormat;
254 	UT_GenericVector<fl_ColProps *> m_vecColProps;
255 	UT_GenericVector<fl_RowProps *> m_vecRowProps;
256 	FL_RowHeightType       m_iRowHeightType;
257 	UT_sint32              m_iRowHeight;
258 
259 // table-background properties
260 	PP_PropertyMap::Background	m_background;
261 
262 // table-border properties
263 	UT_RGBColor            m_colorDefault;
264 	PP_PropertyMap::Line   m_lineBottom;
265 	PP_PropertyMap::Line   m_lineLeft;
266 	PP_PropertyMap::Line   m_lineRight;
267 	PP_PropertyMap::Line   m_lineTop;
268 	UT_sint32              m_iNumNestedTables;
269 	bool                   m_bIsEndTableIn;
270     UT_sint32              m_iHeightChanged;
271 	fp_CellContainer *     m_pNewHeightCell;
272 	bool                   m_bDoingDestructor;
273 	UT_sint32              m_iTableWidth;
274 	double                 m_dTableRelWidth;
275 	double                 m_dMaxExtraMargin;
276 };
277 
278 
279 class ABI_EXPORT fl_CellLayout : public fl_SectionLayout
280 {
281 	friend class fl_DocListener;
282 	friend class fp_TableContainer;
283 	friend class fp_CellContainer;
284 public:
285 	fl_CellLayout(FL_DocLayout* pLayout, pf_Frag_Strux* sdh, PT_AttrPropIndex ap, fl_ContainerLayout * pMyContainerLayout);
286 	virtual ~fl_CellLayout();
287 
288 	bool            isCellSelected(void);
289 	void            checkAndAdjustCellSize(void);
290 	virtual bool 	doclistener_changeStrux(const PX_ChangeRecord_StruxChange * pcrxc);
291 	virtual bool    doclistener_deleteStrux(const PX_ChangeRecord_Strux * pcrx);
292 	virtual bool    bl_doclistener_insertCell(fl_ContainerLayout* pCell,
293 											  const PX_ChangeRecord_Strux * pcrx,
294 											  pf_Frag_Strux* sdh,
295 											  PL_ListenerId lid,
296 											  void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
297 																	  PL_ListenerId lid,
298 																	  fl_ContainerLayout* sfhNew));
299 	virtual bool    bl_doclistener_insertEndCell(fl_ContainerLayout*,
300 											  const PX_ChangeRecord_Strux * pcrx,
301 											  pf_Frag_Strux* sdh,
302 											  PL_ListenerId lid,
303 											  void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
304 																	  PL_ListenerId lid,
305 																	  fl_ContainerLayout* sfhNew));
306 
307 	void                     setCellContainerProperties(fp_CellContainer * pCell);
308 	void                     createCellContainer(void);
309 	virtual void		     format(void);
310 	virtual void		     updateLayout(bool bDoFull);
311 	virtual void             collapse(void);
312 	bool                     isLayedOut(void) const;
313 	bool                     isDoingFormat(void) const;
314 	virtual bool             needsReformat(void) const;
315 	virtual void             markAllRunsDirty(void);
316 	virtual fl_SectionLayout *  getSectionLayout(void)  const;
317 	bool                     recalculateFields(UT_uint32 iUpdateCount);
318 	virtual void		     redrawUpdate(void);
319 	virtual fp_Container*	 getNewContainer(fp_Container * pFirstContainer = NULL);
320 #ifdef FMT_TEST
321 	void				     __dump(FILE * fp) const;
322 #endif
323 	UT_uint32                   getLength(void);
324 
325 	UT_sint32                getLeftOffset(void) const;
326 UT_sint32                    getRightOffset(void) const;
327 	UT_sint32                getTopOffset(void) const;
328 UT_sint32                    getBottomOffset(void) const;
329 	UT_sint32                getNumNestedTables(void) const;
330 	void                     incNumNestedTables(void);
331 	void                     decNumNestedTables(void);
getLeftAttach(void)332 	UT_sint32                getLeftAttach(void) const
333 		{ return m_iLeftAttach;}
getRightAttach(void)334 	UT_sint32                getRightAttach(void) const
335 		{ return m_iRightAttach;}
getTopAttach(void)336 	UT_sint32                getTopAttach(void) const
337 		{ return m_iTopAttach;}
getBottomAttach(void)338 	UT_sint32                getBottomAttach(void) const
339 		{ return m_iBottomAttach;}
getCellHeight(void)340 	UT_sint32                getCellHeight(void) const
341 		{ return m_iCellHeight;}
getCellWidth(void)342 	UT_sint32                getCellWidth(void) const
343 		{ return m_iCellWidth;}
344 
345 protected:
346 	virtual void		     _lookupProperties(const PP_AttrProp* pAP);
347 	virtual void             _purgeLayout(void);
348 private:
349 	bool                   m_bNeedsRebuild;
350 	UT_sint32              m_iLeftOffset;
351 	double                 m_dLeftOffsetUserUnits;
352 	UT_sint32              m_iRightOffset;
353 	double                 m_dRightOffsetUserUnits;
354 	UT_sint32              m_iTopOffset;
355 	double                 m_dTopOffsetUserUnits;
356 	UT_sint32              m_iBottomOffset;
357 	double                 m_dBottomOffsetUserUnits;
358 
359 	UT_sint32              m_iLeftAttach;
360 	UT_sint32              m_iRightAttach;
361 	UT_sint32              m_iTopAttach;
362 	UT_sint32              m_iBottomAttach;
363 
364 	bool                   m_bCellPositionedOnPage;
365 	UT_sint32              m_iCellHeight;
366 	UT_sint32              m_iCellWidth;
367 
368 // cell-background properties
369 	PP_PropertyMap::Background	m_background;
370 
371 // cell-border properties
372 	PP_PropertyMap::Line   m_lineBottom;
373 	PP_PropertyMap::Line   m_lineLeft;
374 	PP_PropertyMap::Line   m_lineRight;
375 	PP_PropertyMap::Line   m_lineTop;
376 
377 	void                   _updateCell(void);
378 	void                   _localCollapse();
379 	UT_sint32              m_iNumNestedTables;
380 	bool                   m_bDoingFormat;
381 
382 // Vertical alignment property
383 	UT_sint32	m_iVertAlign;
384 
385 };
386 
387 ///
388 /// Define the current supported background fill types
389 /// DO NOT CHANGE THE EXISTING NUMBERS, EVER!
390 /// You can add new styles as you please
391 ///
392 #define FS_OFF	0		// No fill style
393 #define FS_FILL	1		// Solid fill style
394 // add more fill styles here
395 
396 ///
397 /// Define the current supported line style types
398 /// DO NOT CHANGE THE NUMBERS, EVER!
399 /// You can add new styles as you please
400 ///
401 #define LS_OFF		0	// No line style, which means no line is drawn
402 #define LS_NORMAL	1	// A normal solid line
403 #define LS_DOTTED	2	// A dotted line
404 #define LS_DASHED	3	// A dashed line
405 // add more line styles here
406 
407 #endif /* TABLELAYOUT_H */
408