1 /* AbiSource
2  *
3  * Copyright (C) 2005 INdT
4  * Author: Daniel d'Andrada T. de Carvalho <daniel.carvalho@indt.org.br>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA.
20  */
21 
22 #ifndef ODE_TABLE_LISTENER_H_
23 #define ODE_TABLE_LISTENER_H_
24 
25 // Internal includes
26 #include "ODe_AbiDocListenerImpl.h"
27 #include "ODe_Common.h"
28 #include "ODe_Style_Style.h"
29 
30 // AbiWord includes
31 #include <ut_string_class.h>
32 #include <ut_vector.h>
33 
34 // External includes
35 #include <stdio.h>
36 
37 // Internal classes
38 class ODe_AutomaticStyles;
39 class ODe_AuxiliaryData;
40 class ODe_Styles;
41 
42 
43 /**
44  * A <table:table-cell> element
45  */
46 class ODe_Table_Cell {
47 public:
48 
ODe_Table_Cell()49     ODe_Table_Cell() : m_pTextContent(NULL) {}
50 
~ODe_Table_Cell()51     ~ODe_Table_Cell() {
52         if (m_pTextContent != NULL) {
53             ODe_gsf_output_close(m_pTextContent);
54         }
55     }
56 
57     void loadAbiProps(const PP_AttrProp* pAP);
58 
59     void write(GsfOutput* pTableOutput, const UT_UTF8String& rSpacesOffset);
60 
61     // <table:table-cell>
62     UT_UTF8String m_numberColumnsSpanned; // table:number-columns-spanned
63     UT_UTF8String m_numberRowsSpanned;    // table:number-columns-spanned
64     UT_UTF8String m_styleName;            // table:style-name
65 
66     // A temporary holder for its text content.
67     GsfOutput* m_pTextContent;
68 
69     // From AbiWord <cell> element
70     UT_sint32 m_leftAttach, m_rightAttach, m_topAttach, m_bottomAttach;
71 
72     // xml:id
73     UT_UTF8String m_xmlid;
74 };
75 
76 
77 /**
78  * A table column. It just contains column formating info, not holding any cells.
79  * The cells are stored on the table rows.
80  */
81 class ODe_Table_Column {
82 public:
83     void write(GsfOutput* pTableOutput, const UT_UTF8String& rSpacesOffset);
84 
85     // <table:table-column>
86     UT_UTF8String m_styleName; // table:style-name
87 };
88 
89 
90 /**
91  * A table row. Contains row formating info and also holds its cells.
92  */
93 class ODe_Table_Row {
94 public:
95 
96     ODe_Table_Row();
97     ~ODe_Table_Row();
98 
99     void write(GsfOutput* pTableOutput, const UT_UTF8String& rSpacesOffset);
100 
101     // A NULL value means that this cell is covered, that it's a
102     // <table:covered-table-cell/> element
103     ODe_Table_Cell** m_ppCells;
104 
105     // <table:table-row>
106     UT_UTF8String m_styleName; // table:style-name
107 
108     UT_uint32 m_columnCount;
109 };
110 
111 
112 /**
113  * Handles an abi <table> element, writing, as output, it's OpenDocument
114  * <table:table> counterpart.
115  */
116 class ODe_Table_Listener : public ODe_AbiDocListenerImpl {
117 public:
118 
119     ODe_Table_Listener(ODe_Styles& rStyles,
120                        ODe_AutomaticStyles& rAutomatiStyles,
121                        GsfOutput* pTextOutput,
122                        ODe_AuxiliaryData& rAuxiliaryData,
123                        UT_uint8 zIndex,
124                        UT_uint8 spacesOffset);
125 
126     virtual ~ODe_Table_Listener();
127 
128     virtual void openTable(const PP_AttrProp* pAP, ODe_ListenerAction& rAction);
129     virtual void closeTable(ODe_ListenerAction& rAction);
130 
131     virtual void openCell(const PP_AttrProp* pAP, ODe_ListenerAction& rAction);
132 
133 private:
134     void _buildTable();
135 
136     ODe_Table_Column* m_pColumns;
137     UT_sint32 m_numColumns;
138 
139     ODe_Table_Row* m_pRows;
140     UT_sint32 m_numRows;
141 
142     UT_GenericVector<ODe_Table_Cell*> m_cells;
143 
144     GsfOutput* m_pTextOutput;
145 	ODe_Styles& m_rStyles;
146     ODe_AutomaticStyles& m_rAutomatiStyles;
147     ODe_AuxiliaryData& m_rAuxiliaryData;
148     UT_uint8 m_zIndex;
149 
150     UT_UTF8String m_tableName;
151     UT_UTF8String m_tableStyleName;
152 
153     // Abiword has table-wide cell properties (i.e.: cell properties inside
154     // <table> element), but OpenDocument doesn't.
155     // So I have to propagate this properties into every cell of this table.
156     ODe_Style_Style m_tableWideCellStyle;
157     UT_GenericVector<UT_UTF8String*> columnStyleNames;
158     UT_GenericVector<UT_UTF8String*> rowStyleNames;
159 };
160 
161 #endif /*ODE_TABLE_LISTENER_H_*/
162