home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / wv2 / handlers.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-12  |  12.9 KB  |  315 lines

  1. /* This file is part of the wvWare 2 project
  2.    Copyright (C) 2002-2003 Werner Trobin <trobin@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16.    Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. #ifndef HANDLERS_H
  20. #define HANDLERS_H
  21.  
  22. #include "global.h"
  23. #include "sharedptr.h"
  24. #include "functordata.h"
  25.  
  26. namespace wvWare {
  27.  
  28.     class Parser9x;
  29.     struct UChar;
  30.     class UString;
  31.     template<class ParserT, typename Data> class Functor;
  32.     typedef Functor<Parser9x, HeaderData> HeaderFunctor;
  33.     typedef Functor<Parser9x, TableRowData> TableRowFunctor;
  34.     typedef Functor<Parser9x, FootnoteData> FootnoteFunctor;
  35.  
  36.     /**
  37.      * This class allows to replace the character values of some
  38.      * characters in a Word document, like non-breaking hyphens,...
  39.      * during the processing. As we have to look at every single
  40.      * character anyway, we can as well do single-character replacement
  41.      * in case it's necessary. That way you don't have to scan all the
  42.      * text again in the consumer filter.
  43.      *
  44.      * We use U8 instead of U16 as all interesting Word characters are
  45.      * within 7bit ASCII range, the names of the methods should be
  46.      * descriptive enough.
  47.      */
  48.     class InlineReplacementHandler
  49.     {
  50.     public:
  51.         virtual ~InlineReplacementHandler();
  52.  
  53.         virtual U8 tab();
  54.         virtual U8 hardLineBreak();
  55.         virtual U8 columnBreak();
  56.         virtual U8 nonBreakingHyphen();
  57.         virtual U8 nonRequiredHyphen();
  58.         virtual U8 nonBreakingSpace();
  59.     };
  60.  
  61.  
  62.     /**
  63.      * The SubDocumentHandler is more or less a state-callback class. It informs
  64.      * the consumer filter about changes of subdocuments like body, header,
  65.      * footnote,...
  66.      * This class is needed as we reuse one @ref TextHandler object for all the
  67.      * text we find, no matter whether it's inside the main body or within a textbox.
  68.      */
  69.     class WV2_DLLEXPORT SubDocumentHandler
  70.     {
  71.     public:
  72.         virtual ~SubDocumentHandler();
  73.  
  74.         /**
  75.          * This method is called as soon as you call @ref Parser::parse. It indicates
  76.          * the start of the body text (the main document text-flow).
  77.          */
  78.         virtual void bodyStart();
  79.         /**
  80.          * This method is called when all characters of the main body text
  81.          * are processed.
  82.          */
  83.         virtual void bodyEnd();
  84.  
  85.         /**
  86.          * Every time you invoke a @ref FoonoteFunctor this method will be called.
  87.          * Note that @ref FoonoteFunctor is also emitted when we find endnotes.
  88.          */
  89.         virtual void footnoteStart();
  90.         /**
  91.          * Once the footnote characters are processed this method is called.
  92.          */
  93.         virtual void footnoteEnd();
  94.  
  95.         /**
  96.          * For every section in a Word document a @ref HeaderFunctor is emitted.
  97.          * Invoking the functor triggers the parsing of all headers inside the
  98.          * section, this method is called to indicate that.
  99.          */
  100.         virtual void headersStart();
  101.         /**
  102.          * This method is called once all headers and footers of the current
  103.          * section are processed.
  104.          */
  105.         virtual void headersEnd();
  106.         /**
  107.          * There are up to 6 headers/footers for every section. This method informs
  108.          * you about the begin of a new header or footer of the given type.
  109.          *
  110.          * The default header/footer is the *Odd one. If you also get any *Even
  111.          * header or footer the document's left and right pages have different
  112.          * headers/footers. In case you get a *First header or footer the first
  113.          * page of this section has a different header or footer.
  114.          *
  115.          * @param type The type of the header or footer. Always emitted in
  116.          *             the order of definition in the enum
  117.          */
  118.         virtual void headerStart( HeaderData::Type type );
  119.         /**
  120.          * The end of the current header or footer.
  121.          */
  122.         virtual void headerEnd();
  123.     };
  124.  
  125.  
  126.     namespace Word97
  127.     {
  128.         struct TAP;
  129.     }
  130.  
  131.     /**
  132.      * The TableHandler class is the interface for all table related callbacks.
  133.      * It informs about about starts and ends of table cells and rows.
  134.      * Only invoking a table row functor triggers the parsing of the given table
  135.      * row, and results in table(Row|Cell)(Start|End) callbacks.
  136.      *
  137.      * Word doesn't store information about table boundaries internally, but
  138.      * it's quite easy to find out the start/end of a table, as all table
  139.      * row functors are emitted in a row (pun intended). This means that if
  140.      * you get a sequence of table row functors and then suddenly a
  141.      * paragraphStart callback, you know that the table has ended.
  142.      */
  143.     class WV2_DLLEXPORT TableHandler
  144.     {
  145.     public:
  146.         virtual ~TableHandler();
  147.  
  148.         /**
  149.          * Indicates the start of a table row with the passed properties.
  150.          */
  151.         virtual void tableRowStart( SharedPtr<const Word97::TAP> tap );
  152.         /**
  153.          * Indicates the end of a table row.
  154.          */
  155.         virtual void tableRowEnd();
  156.         /**
  157.          * This method is invoked every time we start processing a new cell.
  158.          */
  159.         virtual void tableCellStart();
  160.         /**
  161.          * This method is invoked every time we reach a cell end.
  162.          */
  163.         virtual void tableCellEnd();
  164.     };
  165.  
  166.  
  167.     class ParagraphProperties;
  168.     struct FLD;
  169.     namespace Word97
  170.     {
  171.         struct CHP;
  172.         struct SEP;
  173.     }
  174.  
  175.     /**
  176.      * The TextHandler class is the main worker in this filter. It tells you
  177.      * about sections, paragraphs, and characters inside the document. If
  178.      * you want to have a fast filter, try to make those methods fast, they
  179.      * will get called very oftern.
  180.      */
  181.     class WV2_DLLEXPORT TextHandler
  182.     {
  183.     public:
  184.         virtual ~TextHandler();
  185.  
  186.         //////////////////////////////////////////////////////////////////////
  187.         // Section related callbacks...
  188.         /**
  189.          * Denotes the start of a section.
  190.          * The section properties are passed in the @p sep argument.
  191.          */
  192.         virtual void sectionStart( SharedPtr<const Word97::SEP> sep );
  193.         virtual void sectionEnd();
  194.         /**
  195.          * A page break within a section.
  196.          */
  197.         virtual void pageBreak();
  198.         /**
  199.          * Emitted when we found headers or footers. The default implementation
  200.          * simply invokes the functor. This function is called right after the
  201.          * start of a new section.
  202.          */
  203.         virtual void headersFound( const HeaderFunctor& parseHeaders );
  204.  
  205.         //////////////////////////////////////////////////////////////////////
  206.         // Paragraph related callbacks...
  207.         /**
  208.          * Denotes the start of a paragraph.
  209.          * The paragraph properties are passed in the @p paragraphProperties argument.
  210.          */
  211.         virtual void paragraphStart( SharedPtr<const ParagraphProperties> paragraphProperties );
  212.         virtual void paragraphEnd();
  213.  
  214.         /**
  215.          * runOfText is the main worker in this API. It provides a chunk of text with
  216.          * the properties passed. A run of text inside a Word document may encompass
  217.          * an entire document, but in our implementation we chop those runs of text into
  218.          * smaller pieces.
  219.          * A run of text will never cross paragraph boundaries, even if the paragraph
  220.          * properties of the two or more containing paragraphs are the same. It would
  221.          * probably be slightly faster to do that, but IMHO it's just not worth the
  222.          * pain this would cause.
  223.          * @param text The text of this run, UString holds it as UCS-2 host order string.
  224.          * @param chp The character properties attached to this run of text
  225.          */
  226.         virtual void runOfText( const UString& text, SharedPtr<const Word97::CHP> chp );
  227.  
  228.         //////////////////////////////////////////////////////////////////////
  229.         // Special characters...
  230.         /**
  231.          * The enum only contains characters which are "easy" to handle (as they don't
  232.          * need any further information). All the other fSpec characters are/will be
  233.          * handled via functors. The values match the ones found in the specification.
  234.          *
  235.          * The current list is just a first draft, I have no idea how many of them will
  236.          * be moved out because they're more complex as expected.
  237.          */
  238.         enum SpecialCharacter { CurrentPageNumber = 0, LineNumber = 6,
  239.                                 AbbreviatedDate = 10, TimeHMS = 11,
  240.                                 CurrentSectionNumber = 12, AbbreviatedDayOfWeek = 14,
  241.                                 DayOfWeek = 15, DayShort = 16, HourCurrentTime = 22,
  242.                                 HourCurrentTimeTwoDigits = 23, MinuteCurrentTime = 24,
  243.                                 MinuteCurrentTimeTwoDigits = 25, SecondsCurrentTime = 26,
  244.                                 AMPMCurrentTime = 27, CurrentTimeHMSOld = 28,
  245.                                 DateM = 29, DateShort = 30, MonthShort = 33,
  246.                                 YearLong = 34, YearShort = 35,
  247.                                 AbbreviatedMonth = 36, MonthLong = 37,
  248.                                 CurrentTimeHMS = 38, DateLong = 39 };
  249.  
  250.         /**
  251.          * Very special characters (bad, bad name) are the ones which need additional
  252.          * information from the file (i.e. the plain "put the current date there" isn't sufficent).
  253.          */
  254.         enum VerySpecialCharacter { Picture = 1, FootnoteAuto = 2, FieldBegin = 19, FieldSeparator = 20,
  255.                                     FieldEnd = 21, FieldEscapeChar = 92 };
  256.  
  257.         /**
  258.          * This method passes the simple cases of special characters we find. More complex ones
  259.          * will get their own callback.
  260.          */
  261.         virtual void specialCharacter( SpecialCharacter character, SharedPtr<const Word97::CHP> chp );
  262.  
  263.         /**
  264.          * The parser found a footnote. The passed functor will trigger the parsing of this
  265.          * footnote/endnote, the default implementation just emits the passed character
  266.          * (unless it's an auto-numbered footnote, we won't emit ASCII 2 by default) with
  267.          * runOfText (that it doesn't get lost if someone doesn't override this method) and
  268.          * invokes the functor.
  269.          */
  270.         virtual void footnoteFound( FootnoteData::Type type, UChar character,
  271.                                     SharedPtr<const Word97::CHP> chp, const FootnoteFunctor& parseFootnote );
  272.         /**
  273.          * This callback will get triggered when parsing a auto-numbered footnote.
  274.          * The passed CHP is the character formatting information provided for the
  275.          * "number"
  276.          */
  277.         virtual void footnoteAutoNumber( SharedPtr<const Word97::CHP> chp );
  278.  
  279.         /**
  280.          * This callback indicates the start of a field. Fields consist of two parts, separated
  281.          * by a field separator.
  282.          * @param fld Describes the type of the field for live fields. May be 0!
  283.          * @param chp The character properties of the field start (ASCII 19)
  284.          */
  285.         virtual void fieldStart( const FLD* fld, SharedPtr<const Word97::CHP> chp );
  286.         /**
  287.          * This callback separates the two parts of a field. The first part contains control
  288.          * codes and keywords, the second part is the field result.
  289.          * @param fld Describes the type of the field for live fields. May be 0!
  290.          * @param chp The character properties of the field separator (ASCII 20)
  291.          */
  292.         virtual void fieldSeparator( const FLD* fld, SharedPtr<const Word97::CHP> chp );
  293.         /**
  294.          * The end of the field result is indicated by this callback, fields may be nested up
  295.          * to 20 levels, so take care :-)
  296.          * @param fld Describes the type of the field for live fields. May be 0!
  297.          * @param chp The character properties of the field end (ASCII 21)
  298.          */
  299.         virtual void fieldEnd( const FLD* fld, SharedPtr<const Word97::CHP> chp );
  300.  
  301.         /**
  302.          * This method is called every time we find a table row. The default
  303.          * implementation invokes the functor, which triggers the parsing
  304.          * process for the given table row.
  305.          * @param tap the table row properties. Those are the same as the
  306.          * ones you'll get when invoking the functor, but by having them here,
  307.          * you can do some preprocessing on the whole table first.
  308.          */
  309.         virtual void tableRowFound( const TableRowFunctor& tableRow, SharedPtr<const Word97::TAP> tap );
  310.     };
  311.  
  312. } // namespace wvWare
  313.  
  314. #endif // HANDLERS_H
  315.