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 / styles.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-12  |  6.1 KB  |  287 lines

  1. /* This file is part of the wvWare 2 project
  2.    Copyright (C) 2001-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 STYLES_H
  20. #define STYLES_H
  21.  
  22. #include "word97_generated.h"
  23.  
  24. namespace wvWare
  25. {
  26.  
  27. class OLEStreamReader;
  28. class OLEStreamWriter;
  29.  
  30. namespace Word97
  31. {
  32.  
  33. /**
  34.  * STyle Definition (STD)
  35.  */
  36. struct STD
  37. {
  38.     /**
  39.      * Creates an empty STD structure and sets the defaults
  40.      */
  41.     STD();
  42.     /**
  43.      * Simply calls read(...)
  44.      */
  45.     STD( U16 baseSize, U16 totalSize, OLEStreamReader* stream, bool preservePos = false );
  46.     /**
  47.      * Attention: This struct allocates memory on the heap
  48.      */
  49.     STD( const STD& rhs );
  50.     ~STD();
  51.  
  52.     STD& operator=( const STD& rhs );
  53.  
  54.     /**
  55.      * This method reads the STD structure from the stream.
  56.      * If  preservePos is true we push/pop the position of
  57.      * the stream to save the state. If it's false the state
  58.      * of stream will be changed!
  59.      */
  60.     bool read( U16 baseSize, U16 totalSize, OLEStreamReader* stream, bool preservePos = false );
  61.  
  62.     /**
  63.      * Same as reading :)
  64.      */
  65.     bool write( U16 baseSize, OLEStreamWriter* stream, bool preservePos = false ) const;
  66.  
  67.     /**
  68.      * Set all the fields to the inital value (default is 0)
  69.      */
  70.     void clear();
  71.  
  72.     // Data
  73.     /**
  74.      * invariant style identifier
  75.      */
  76.     U16 sti:12;
  77.  
  78.     /**
  79.      * spare field for any temporary use, always reset back to zero!
  80.      */
  81.     U16 fScratch:1;
  82.  
  83.     /**
  84.      * PHEs of all text with this style are wrong
  85.      */
  86.     U16 fInvalHeight:1;
  87.  
  88.     /**
  89.      * UPEs have been generated
  90.      */
  91.     U16 fHasUpe:1;
  92.  
  93.     /**
  94.      * std has been mass-copied; if unused at save time, style should be deleted
  95.      */
  96.     U16 fMassCopy:1;
  97.  
  98.     /**
  99.      * style type code
  100.      */
  101.     U16 sgc:4;
  102.  
  103.     /**
  104.      * base style
  105.      */
  106.     U16 istdBase:12;
  107.  
  108.     /**
  109.      * # of UPXs (and UPEs)
  110.      */
  111.     U16 cupx:4;
  112.  
  113.     /**
  114.      * next style
  115.      */
  116.     U16 istdNext:12;
  117.  
  118.     /**
  119.      * offset to end of upx's, start of upe's
  120.      */
  121.     U16 bchUpe;
  122.  
  123.     /**
  124.      * auto redefine style when appropriate
  125.      */
  126.     U16 fAutoRedef:1;
  127.  
  128.     /**
  129.      * hidden from UI?
  130.      */
  131.     U16 fHidden:1;
  132.  
  133.     /**
  134.      * unused bits
  135.      */
  136.     U16 unused8_3:14;
  137.  
  138.     /**
  139.      * sub-names are separated by chDelimStyle
  140.      */
  141.     UString xstzName;
  142.  
  143.     U8* grupx;
  144.  
  145.     // Internal, for bookkeeping
  146.     U16 grupxLen;
  147.  
  148. private:
  149.     void clearInternal();
  150.     void readStyleName( U16 baseSize, OLEStreamReader* stream );
  151. }; // STD
  152.  
  153. bool operator==( const STD& lhs, const STD& rhs );
  154. bool operator!=( const STD& lhs, const STD& rhs );
  155.  
  156. }  // namespace Word97
  157.  
  158.  
  159. class StyleSheet;
  160. class ParagraphProperties;
  161. class ListInfoProvider;
  162.  
  163. // The structure to hold the UPE for character styles.
  164. struct UPECHPX
  165. {
  166.     UPECHPX() : istd( 0 ), cb( 0 ), grpprl( 0 ) {}
  167.     ~UPECHPX() { delete [] grpprl; }
  168.  
  169.     U16 istd;
  170.     U8 cb;
  171.     U8* grpprl;
  172.  
  173. private:
  174.     UPECHPX( const UPECHPX& rhs );
  175.     UPECHPX& operator=( const UPECHPX& rhs );
  176. };
  177.  
  178. /**
  179.  * This class represents one single style.
  180.  */
  181. // It would maybe be worth to optimize the construction a bit, like creating
  182. // the PAP and the CHP on copying from the base style, and not before (TODO)
  183. class Style
  184. {
  185. public:
  186.     enum StyleType { sgcUnknown = 0, sgcPara = 1, sgcChp = 2 };
  187.  
  188.     Style( U16 baseSize, OLEStreamReader* tableStream, U16* ftc );
  189.     ~Style();
  190.  
  191.     /**
  192.      * The stylesheet can have "empty" slots
  193.      */
  194.     bool isEmpty() const { return m_isEmpty; }
  195.     /**
  196.      * Did we already unwrap the style?
  197.      */
  198.     bool isWrapped() const { return m_isWrapped; }
  199.  
  200.     /**
  201.      * Unwrap the style and create a valid PAP/CHP
  202.      */
  203.     void unwrapStyle( const StyleSheet& stylesheet, WordVersion version );
  204.  
  205.     /**
  206.      * Get the (unique?) sti of that style
  207.      */
  208.     U16 sti() const;
  209.  
  210.     /**
  211.      * Get the type of the style (paragraph/character style)
  212.      */
  213.     StyleType type() const;
  214.  
  215.     /**
  216.      * Style name
  217.      */
  218.     UString name() const;
  219.  
  220.     /**
  221.      * Id of following style
  222.      */
  223.     U16 followingStyle() const;
  224.  
  225.     /*
  226.      * For paragraph styles only
  227.      */
  228.     const ParagraphProperties& paragraphProperties() const;
  229.     /*
  230.      * For paragraph styles only
  231.      */
  232.     const Word97::CHP& chp() const;
  233.     /*
  234.      * For character styles only
  235.      */
  236.     const UPECHPX& upechpx() const;
  237.  
  238. private:
  239.     Style( const Style& rhs );
  240.     Style& operator=( const Style& rhs );
  241.  
  242.     // This helper method merges two CHPX structures to one
  243.     // (needed for character styles)
  244.     void mergeUpechpx( const Style* parentStyle, WordVersion version );
  245.  
  246.     bool m_isEmpty;
  247.     bool m_isWrapped;
  248.     Word97::STD* m_std;
  249.  
  250.     mutable ParagraphProperties *m_properties; // "mutable" in case someone goes mad
  251.     mutable Word97::CHP *m_chp; //  with the styles. We have to create a default style
  252.     mutable UPECHPX *m_upechpx; // to avoid crashes and still have to keep ownership!
  253. };
  254.  
  255.  
  256. /**
  257.  * This class holds all the styles this Word document
  258.  * defines. You can query styles by ID (sti) or index (istd)
  259.  */
  260. class StyleSheet
  261. {
  262. public:
  263.     StyleSheet( OLEStreamReader* tableStream, U32 fcStshf, U32 lcbStshf );
  264.     ~StyleSheet();
  265.  
  266.     /**
  267.      * Return the number of styles.
  268.      */
  269.     unsigned int size() const;
  270.     const Style* styleByIndex( U16 istd ) const;
  271.  
  272.     const Style* styleByID( U16 sti ) const;
  273.  
  274.     U16 indexByID( U16 sti, bool& ok ) const;
  275.  
  276. private:
  277.     StyleSheet( const StyleSheet& rhs );
  278.     StyleSheet& operator=( const StyleSheet& rhs );
  279.  
  280.     Word97::STSHI m_stsh;
  281.     std::vector<Style*> m_styles;
  282. };
  283.  
  284. }  // namespace wvWare
  285.  
  286. #endif // STYLES_H
  287.