filters

tablehandler.h

00001 /* This file is part of the KOffice project
00002    Copyright (C) 2002 Werner Trobin <trobin@kde.org>
00003    Copyright (C) 2002 David Faure <faure@kde.org>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef TABLEHANDLER_H
00021 #define TABLEHANDLER_H
00022 
00023 #include <wv2/functor.h>
00024 #include <wv2/word97_generated.h> // for TAP
00025 #include <wv2/handlers.h>
00026 #include <qstring.h>
00027 #include <qvaluelist.h>
00028 #include <qobject.h>
00029 #include <deque>
00030 
00031 namespace wvWare {
00032     namespace Word97 {
00033         class TC;
00034         class SHD;
00035     }
00036 }
00037 class KoRect;
00038 
00039 namespace KWord
00040 {
00041     typedef const wvWare::TableRowFunctor* TableRowFunctorPtr;
00042     typedef wvWare::SharedPtr<const wvWare::Word97::TAP> TAPptr;
00043 
00044     // Data for a given row table. This struct is used by the Table struct.
00045     struct Row
00046     {
00047         Row() : functorPtr( 0L ), tap( 0L )  {} // QValueList wants that one
00048         Row( TableRowFunctorPtr ptr, TAPptr _tap ) : functorPtr(ptr), tap(_tap) {}
00049         ~Row() {}
00050 
00051         // Each row has: a functor to call to parse it and a TAP (table row properties)
00052         TableRowFunctorPtr functorPtr;
00053         TAPptr tap;
00054     };
00055 
00056     // Data for a given table, stored between the 'tableRowFound' callback
00057     // during text parsing and the final generation of table cells.
00058     struct Table
00059     {
00060         QString name; // kword's grpMgr attribute
00061         QValueList<Row> rows; // need to use QValueList to benefit from implicit sharing
00062 
00063         // Word has a very flexible concept of columns: each row can vary the
00064         // edges of each column. We must map this onto a set of fixed-width columns
00065         // by defining columns on each edge, and then using joined cells to model
00066         // the original Word cells. We accumulate all the known edges for a given
00067         // table in an array.
00068         // Important: don't use unsigned int. Value can be negative (relative to margin...).
00069         QMemArray<int> m_cellEdges;
00070 
00071         void cacheCellEdge( int cellEdge );
00072         int columnNumber( int cellEdge ) const;
00073     };
00074 }
00075 
00076 class KWordTableHandler : public QObject, public wvWare::TableHandler
00077 {
00078     Q_OBJECT
00079 public:
00080     KWordTableHandler();
00081 
00083     virtual void tableRowStart( wvWare::SharedPtr<const wvWare::Word97::TAP> tap );
00084     virtual void tableRowEnd();
00085     virtual void tableCellStart();
00086     virtual void tableCellEnd();
00087 
00089     void tableStart( KWord::Table* table );
00090     void tableEnd();
00091 
00092 signals:
00093     // Tells Document to create frameset for cell
00094     void sigTableCellStart( int row, int column, int rowSpan, int columnSpan, const KoRect& cellRect, const QString& tableName, const wvWare::Word97::BRC& brcTop, const wvWare::Word97::BRC& brcBottom, const wvWare::Word97::BRC& brcLeft, const wvWare::Word97::BRC& brcRight, const wvWare::Word97::SHD& shd );
00095     void sigTableCellEnd();
00096 
00097 protected:
00098     double rowHeight() const;
00099 
00100 private:
00101     KWord::Table* m_currentTable;
00102     int m_row;
00103     int m_column;
00104     double m_currentY;
00105     wvWare::SharedPtr<const wvWare::Word97::TAP> m_tap;
00106 };
00107 
00108 #endif // TABLEHANDLER_H
KDE Home | KDE Accessibility Home | Description of Access Keys