• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ie_Table.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiWord
00004  * Copyright (C) 2002 Martin Sevior <msevior@physics.unimelb.edu.au>
00005  * Copyright (C) 2003 Francis James Franklin <fjf@alinameridon.com>
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020  * 02110-1301 USA.
00021  */
00022 
00023 #ifndef IE_TABLES
00024 #define IE_TABLES
00025 
00026 #include <stack>
00027 #include <string>
00028 
00029 #include "pd_Document.h"
00030 #include "pt_Types.h"
00031 #include "ut_wctomb.h"
00032 
00033 class PD_Document;
00034 class PX_ChangeRecord_Object;
00035 class PP_AttrProp;
00036 class ie_imp_table;
00037 
00038 
00039 class ABI_EXPORT ie_PartTable
00040 {
00041  public:
00042     ie_PartTable(PD_Document * pDoc);
00043     virtual ~ie_PartTable(void);
00044     void             setDoc(PD_Document * pDoc);
00045     void             setTableApi(pf_Frag_Strux* sdh,PT_AttrPropIndex iApi);
00046     void             setCellApi(PT_AttrPropIndex iApi);
00047     UT_sint32        getLeft(void) const;
00048     UT_sint32        getRight(void) const;
00049     UT_sint32        getPrevRight(void) const {return m_iPrevRight;}
00050     UT_sint32        getTop(void) const;
00051     UT_sint32        getBot(void) const;
00052     const char *     getTableProp(const char * pPropName) const;
00053     const char *     getCellProp(const char * pPropName) const;
00054     PT_AttrPropIndex getTableAPI(void) const {return m_apiTable;}
00055     PT_AttrPropIndex getCellAPI(void) const { return m_apiCell;}
00056     UT_sint32        getNumRows(void) const;
00057     UT_sint32        getNumCols(void) const;
00058     UT_sint32        getCurRow(void) const { return m_iCurRow;}
00059     void             incCurRow(void) { m_iCurRow++;}
00060     pf_Frag_Strux* getTableSDH(void) const
00061         { return m_TableSDH;}
00062     void             setCellJustOpenned(bool b);
00063     bool             isCellJustOpenned(void) const;
00064  private:
00065     void                  _setRowsCols(void);
00066     void                  _clearAll(void);
00067     void                  _clearAllCell(void);
00068     PD_Document *         m_pDoc;
00069     PT_AttrPropIndex      m_apiTable;
00070     PT_AttrPropIndex      m_apiCell;
00071     const PP_AttrProp *   m_TableAttProp;
00072     const PP_AttrProp *   m_CellAttProp;
00073     UT_sint32             m_iNumRows;
00074     UT_sint32             m_iNumCols;
00075     UT_sint32             m_iLeft;
00076     UT_sint32             m_iRight;
00077     UT_sint32             m_iTop;
00078     UT_sint32             m_iBot;
00079     UT_sint32             m_iPrevLeft;
00080     UT_sint32             m_iPrevRight;
00081     UT_sint32             m_iPrevTop;
00082     UT_sint32             m_iPrevBot;
00083     pf_Frag_Strux*     m_TableSDH;
00084     bool                  m_bIsCellJustOpenned;
00085     UT_sint32             m_iCurRow;
00086 };
00087 
00088 
00089 class ABI_EXPORT ie_Table
00090 {
00091  public:
00092     ie_Table(PD_Document * pDoc);
00093     ie_Table(void);
00094     virtual ~ie_Table(void);
00095     void             setDoc(PD_Document * pDoc);
00096     void             openTable(pf_Frag_Strux* tableSDH, PT_AttrPropIndex iApi);
00097     void             openCell(PT_AttrPropIndex iApi);
00098     void             closeTable(void);
00099     void             closeCell(void);
00100     bool             isNewRow(void) const;
00101     UT_sint32        getLeft(void) const;
00102     UT_sint32        getRight(void) const;
00103     UT_sint32        getTop(void) const;
00104     UT_sint32        getBot(void) const;
00105     UT_sint32        getNumRows(void) const;
00106     UT_sint32        getNumCols(void) const;
00107     const char *     getTableProp(const char * pPropName) const;
00108     const char *     getCellProp(const char * pPropName) const;
00109     UT_sint32        getNestDepth(void) const;
00110     void             setCellRowCol(UT_sint32 row, UT_sint32 col);
00111     pf_Frag_Strux*   getTableSDH(void) const;
00112     void             setCellJustOpenned(bool b);
00113     bool             isCellJustOpenned(void) const;
00114     PT_AttrPropIndex getTableAPI(void) const;
00115     PT_AttrPropIndex getCellAPI(void) const;
00116     UT_sint32        getPrevNumRightMostVMerged(void) const;
00117     UT_sint32        getCurRow(void) const;
00118     void             incCurRow(void);
00119  private:
00120     void             _clearLastTables();
00121     PD_Document *    m_pDoc;
00122     std::stack<ie_PartTable*> m_sLastTable;
00123     bool             m_bNewRow;
00124     pf_Frag_Strux*   m_sdhLastCell;
00125 };
00126 
00127 
00128 class ABI_EXPORT ie_imp_cell
00129 {
00130  public:
00131     ie_imp_cell(ie_imp_table * pImpTable, PD_Document * pDoc,
00132                 ie_imp_cell * pImpCell, UT_sint32 iRow);
00133     virtual          ~ie_imp_cell(void);
00134     void             setCellX(UT_sint32 cellx);
00135     UT_sint32        getCellX(void) const;
00136     void             setCellLeft(ie_imp_cell * pImpCell);
00137     void             setLeft(UT_sint32 iLeft);
00138     UT_sint32        getLeft(void) const;
00139     void             setRight(UT_sint32 iRight);
00140     UT_sint32        getRight(void) const;
00141     void             setTop(UT_sint32 iTop);
00142     UT_sint32        getTop(void) const;
00143     void             setBot(UT_sint32 iBot);
00144     UT_sint32        getBot(void) const;
00145     pf_Frag_Strux* getCellSDH(void) const;
00146     void             setCellSDH(pf_Frag_Strux* cellSDH);
00147     bool             writeCellPropsInDoc(void) const;
00148     ie_imp_cell *    getCellAbove(void) const;
00149     ie_imp_cell *    getCellBelow(void) const;
00150     ie_imp_cell *    getCellLeft(void) const;
00151     ie_imp_cell *    getCellRight(void) const;
00152     void             addPropString(const std::string & sPropString);
00153     void             setProp(const std::string & psProp,
00154                              const std::string & psVal);
00155     std::string      getPropVal(const std::string & psProp) const;
00156     void             setProp(const char * szProp, const char * szVal);
00157     std::string        getPropVal(const char * szProp) const;
00158     UT_sint32        getRow(void) const { return m_iRow;}
00159     void             setMergeAbove(bool bAbove) { m_bMergeAbove = bAbove;}
00160     void             setMergeRight(bool bRight) {m_bMergeRight = bRight;}
00161     void             setMergeLeft(bool bLeft) {m_bMergeLeft = bLeft;}
00162     void             setFirstHorizontalMerge(bool bHori) {m_bFirstHori = bHori;}
00163     void             setFirstVerticalMerge( bool bVert) {m_bFirstVertical = bVert;}
00164     bool             isMergedAbove(void )const {return m_bMergeAbove;}
00165     bool             isMergedRight(void) const {return m_bMergeRight;}
00166     bool             isMergedLeft(void) const {return m_bMergeLeft;}
00167     bool             isFirstVerticalMerged(void) const {return m_bFirstVertical;}
00168     bool             isFirstHorizontalMerged(void) const {return m_bFirstHori;}
00169     void             copyCell(ie_imp_cell * pCell);
00170     void             setImpTable(ie_imp_table * pTable) { m_pImpTable = pTable;}
00171     void             setRow(UT_sint32 row) { m_iRow = row;}
00172  private:
00173     PD_Document *         m_pDoc;
00174     UT_sint32             m_iCellX;
00175     UT_sint32             m_iLeft;
00176     UT_sint32             m_iRight;
00177     UT_sint32             m_iTop;
00178     UT_sint32             m_iBot;
00179     pf_Frag_Strux*     m_cellSDH;
00180     ie_imp_table   *      m_pImpTable;
00181     ie_imp_cell *         m_pCellLeft;
00182     UT_sint32             m_iRow;
00183     bool                  m_bMergeAbove;
00184     bool                  m_bMergeRight;
00185     bool                  m_bMergeLeft;
00186     bool                  m_bFirstVertical;
00187     bool                  m_bFirstHori;
00188     std::string           m_sCellProps;
00189 };
00190 
00191 
00192 class ABI_EXPORT ie_imp_table
00193 {
00194  public:
00195     ie_imp_table(PD_Document * pDoc);
00196     virtual ~ie_imp_table(void);
00197     UT_sint32           OpenCell(void);
00198     UT_sint32           NewRow(void);
00199     void                setCellRowNthCell(UT_sint32 row, UT_sint32 col);
00200     ie_imp_cell *       getNthCellOnRow(UT_sint32 iCell) const;
00201     void                setCellX(UT_sint32 cellx);
00202     pf_Frag_Strux*   getTableSDH(void) const;
00203     void                setTableSDH(pf_Frag_Strux* cellSDH);
00204     void                writeTablePropsInDoc(void);
00205     void                writeAllCellPropsInDoc(void);
00206     void                setProp(const std::string & psProp,
00207                                 const std::string & psVal);
00208     void                setProp(const char *szProp, const char *  szVal);
00209     std::string         getPropVal(const std::string & psProp) const;
00210     std::string         getPropVal(const char * szProp) const;
00211     std::string         getCellPropVal(const std::string & psProp) const;
00212     void                setCellProp(const std::string & psProp,
00213                                     const std::string & psVal);
00214     ie_imp_cell *       getCurCell(void) const;
00215     void                setNthCellOnThisRow(UT_sint32 iCell);
00216     void                buildTableStructure(void);
00217     void                setAutoFit(bool bVal) {m_bAutoFit = bVal;}
00218     bool                isAutoFit(void) const { return m_bAutoFit;}
00219     bool                isNewRow(void) const { return m_bNewRow;}
00220     UT_sint32           getColNumber(ie_imp_cell * pImpCell) const;
00221     ie_imp_cell *       getCellAtRowColX(UT_sint32 newRow,UT_sint32 cellX) const;
00222     void                CloseCell(void);
00223     bool                wasTableUsed(void) const { return m_bTableUsed;}
00224     void                setCell( ie_imp_cell * pCell) { m_pCurImpCell = pCell;}
00225     UT_sint32           getRow(void) const { return m_iRowCounter;}
00226     void                removeExtraneousCells(void);
00227     void                removeOnThisCellRow(ie_imp_cell * pCell);
00228     void                removeCurrentRow(void);
00229     void                deleteRow(UT_sint32 row);
00230     UT_sint32           getNumRows(void) const;
00231     void                setPosOnRow(UT_sint32 posOnRow) { m_iPosOnRow = posOnRow;}
00232     UT_sint32           getPosOnRow(void) const { return m_iPosOnRow;}
00233     void                setCellXOnRow(UT_sint32 cellxOnRow) { m_iCellXOnRow = cellxOnRow;}
00234     UT_sint32           getCellXOnRow(void) const { return m_iCellXOnRow;}
00235     void                incPosOnRow(void) { m_iPosOnRow++;}
00236     void                incCellXOnRow(void) { m_iCellXOnRow++;}
00237     bool                getVecOfCellsOnRow(UT_sint32 row, UT_GenericVector<ie_imp_cell*> * pVec) const;
00238     bool                removeRow(UT_sint32 row);
00239     void                appendRow(UT_GenericVector<ie_imp_cell*>* pVecRowOfCells);
00240     static bool                doCellXMatch(UT_sint32 iCellX1, UT_sint32 iCellX2,bool bIsLast = false);
00241  private:
00242     void                _buildCellXVector(void);
00243     void                _removeAllStruxes(void);
00244     PD_Document *       m_pDoc;
00245     pf_Frag_Strux*   m_tableSDH;
00246     ie_imp_cell *       m_pCurImpCell;
00247     UT_sint32           m_iRowCounter;
00248     std::string           m_sTableProps;
00249     bool                m_bAutoFit;
00250     bool                m_bNewRow;
00251     bool                m_bTableUsed;
00252     UT_sint32           m_iPosOnRow;
00253     UT_sint32           m_iCellXOnRow;
00254     UT_GenericVector<ie_imp_cell*> m_vecCells;
00255     UT_NumberVector           m_vecCellX;
00256     UT_NumberVector           m_vecSavedX;
00257 };
00258 
00259 class ABI_EXPORT ie_imp_table_control
00260 {
00261 public:
00262     ie_imp_table_control(PD_Document * pDoc);
00263     virtual ~ie_imp_table_control(void);
00264     UT_sint32           getNestDepth(void);
00265     void                OpenTable(void);
00266     UT_sint32           OpenCell(void);
00267     void                CloseTable(void);
00268     void                CloseCell(void);
00269     ie_imp_table *      getTable(void) const;
00270     bool                NewRow(void);
00271     void                SaveRowInfo(void);
00272     void                RemoveRowInfo(void);
00273 private:
00274     std::stack<ie_imp_table*> m_sLastTable;
00275     PD_Document *       m_pDoc;
00276 };
00277 
00278 // EXPERIMENTAL CODE
00279 #define USE_IE_IMP_TABLEHELPER 1
00280 
00281 #ifdef USE_IE_IMP_TABLEHELPER
00282 enum TableZone
00283     {
00284         /* tz_caption, */
00285         tz_head,
00286         tz_foot,
00287         tz_body
00288     };
00289 class ABI_EXPORT CellHelper
00290 {
00291 public:
00292     CellHelper ();
00293     void setProp(const char * szProp, const std::string& sVal);
00294     std::string     m_style;
00295 
00296         /* cell frag/strux
00297          */
00298     pf_Frag_Strux *     m_pfsCell;
00299 
00300         /* cell-attach points
00301          */
00302     UT_sint32           m_bottom;
00303     UT_sint32           m_left;
00304     UT_sint32           m_right;
00305     UT_sint32           m_top;
00306 
00307     UT_sint32           m_rowspan;
00308     UT_sint32           m_colspan;
00309 
00310     CellHelper *        m_next;
00311     TableZone           m_tzone;
00312     std::string           m_sCellProps;
00313     bool    isVirtual () const { return (m_next != 0); }
00314 };
00315 
00316 class ABI_EXPORT IE_Imp_TableHelper
00317 {
00318 public:
00319     IE_Imp_TableHelper (PD_Document * pDocument, pf_Frag_Strux * pfsInsertionPoint, const char * style);
00320 
00321     ~IE_Imp_TableHelper ();
00322     bool               tableStart ();
00323 
00324     bool               tableEnd ();
00325     bool               theadStart (const char * style);
00326     bool               tfootStart (const char * style);
00327     bool               tbodyStart (const char * style = 0);
00328 
00329     bool               trStart (const char * style);
00330     bool               tdStart (UT_sint32 rowspan, UT_sint32 colspan, const char * style, pf_Frag_Strux * pfsThis);
00331     /* append/insert methods
00332      */
00333     bool               Block (PTStruxType pts, const PP_PropertyVector & attributes);
00334     bool               BlockFormat (const PP_PropertyVector & attributes);
00335 
00336     bool               Inline (const UT_UCSChar * ucs4_str, UT_sint32 length);
00337     bool               InlineFormat (const PP_PropertyVector & attributes);
00338 
00339     bool               Object (PTObjectType pto, const PP_PropertyVector & attributes);
00340     void               padAllRowsWithCells(UT_GenericVector<CellHelper *> & vecCells,UT_sint32 extra);
00341     void               padRowWithCells(UT_GenericVector<CellHelper *> & vecCells,UT_sint32 row, UT_sint32 extra);
00342     CellHelper *       getCellAtRowCol(UT_GenericVector<CellHelper *> & vecCells, UT_sint32 row, UT_sint32 col) const;
00343     bool               setCaptionOn(void);
00344     bool               setCaptionOff(void);
00345     bool               tdEnd(void) const;
00346 
00347     pf_Frag_Strux *     getInsertionPoint () const { return m_pfsInsertionPoint; }
00348 
00349 private:
00350 
00351     /* 1. Need a section on column definitions, allowing for <col> and <colgroup><col>
00352      * 2. <thead> & <tfoot> should come before <tbody>; any repeats or trailing entries
00353      *    shall be treated as additional <tbody> sections for the moment
00354      */
00355     bool    trEnd ();
00356     void    trClean ();
00357     bool    tdPending () const;
00358 
00359     PD_Document *       m_pDocument;
00360 
00361     std::string     m_style_table;
00362     std::string     m_style_tzone; // thead,tfoot,tbody
00363     std::string     m_style; // tr
00364 
00365     /* cell frag/strux
00366      */
00367     pf_Frag_Strux *     m_pfsInsertionPoint;
00368     pf_Frag_Strux *     m_pfsTableStart;
00369     pf_Frag_Strux *     m_pfsTableEnd;
00370     pf_Frag_Strux *     m_pfsCellPoint;
00371     UT_sint32           m_rows;
00372     UT_sint32           m_rows_head;
00373     UT_sint32           m_rows_head_max;
00374     UT_sint32           m_rows_foot;
00375     UT_sint32           m_rows_foot_max;
00376     UT_sint32           m_rows_body;
00377     UT_sint32           m_rows_body_max;
00378 
00379     UT_sint32           m_cols;
00380     UT_sint32           m_cols_max;
00381 
00382     UT_sint32           m_col_next;
00383     UT_sint32           m_row_next;
00384 
00385     UT_GenericVector<CellHelper *>  m_thead;
00386     UT_GenericVector<CellHelper *>  m_tfoot;
00387     UT_GenericVector<CellHelper *>  m_tbody;
00388 
00389     CellHelper *        m_current;
00390     TableZone           m_tzone;
00391     bool                m_bBlockInsertedForCell;
00392     PD_Document *       getDoc () const { return m_pDocument; }
00393     bool                m_bCaptionOn;
00394 };
00395 
00396 class ABI_EXPORT IE_Imp_TableHelperStack
00397 {
00398 public:
00399     IE_Imp_TableHelperStack (void);
00400 
00401     ~IE_Imp_TableHelperStack ();
00402 
00403     void                    clear ();
00404     IE_Imp_TableHelper *    top () const;
00405 
00406     bool                    tableStart (PD_Document * pDocument, const char * style);
00407     bool                    tableEnd ();
00408 
00409     bool                    theadStart (const char * style) const;
00410     bool                    tfootStart (const char * style) const;
00411     bool                    tbodyStart (const char * style = 0) const;
00412     bool                    trStart (const char * style) const;
00413     bool                    tdStart (UT_sint32 rowspan, UT_sint32 colspan, const char * style) const;
00414 
00415     /* append/insert methods
00416      */
00417     bool                    Block (PTStruxType pts, const PP_PropertyVector & attributes);
00418     bool                    BlockFormat (const PP_PropertyVector & attributes);
00419 
00420     bool                    Inline (const UT_UCSChar * ucs4_str, UT_sint32 length);
00421     bool                    InlineFormat (const PP_PropertyVector & attributes);
00422 
00423     bool                    Object (PTObjectType pto, const PP_PropertyVector & attributes);
00424     bool                    setCaptionOn(void);
00425     bool                    setCaptionOff(void);
00426     bool                    tdEnd(void) const;
00427 private:
00428     PD_Document *           m_pDocument;
00429 
00430     UT_sint32               m_count;
00431     UT_sint32               m_max;
00432 
00433     IE_Imp_TableHelper **   m_stack;
00434     bool                    push (const char * style);
00435     bool                    pop ();
00436 };
00437 
00438 #endif /* USE_IE_IMP_TABLEHELPER */
00439 
00440 #endif /* IE_TABLE */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1