home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / tvision / helpbase.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  4KB  |  183 lines

  1. /*
  2.  * helpbase.h
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. const long magicHeader = 0x46484246L; //"FBHF"
  13.  
  14. #define cHelpViewer "\x06\x07\x08"
  15. #define cHelpWindow "\x80\x81\x82\x83\x84\x85\x86\x87"
  16.  
  17. // TParagraph
  18.  
  19. class TParagraph
  20. {
  21.  
  22. public:
  23.  
  24.     TParagraph() {}
  25.     TParagraph *next;
  26.     Boolean wrap;
  27.     ushort size;
  28.     char *text;
  29.  
  30. };
  31.  
  32. // TCrossRef
  33.  
  34. class TCrossRef
  35. {
  36.  
  37. public:
  38.  
  39.     TCrossRef() {}
  40.     int ref;
  41.     int offset;
  42.     uchar length;
  43.  
  44. };
  45.  
  46.  
  47. typedef void (*TCrossRefHandler) ( opstream&, int );
  48.  
  49. class THelpTopic: public TObject, public TStreamable
  50. {
  51.  
  52. public:
  53.  
  54.     THelpTopic();
  55.     THelpTopic( StreamableInit ) {};
  56.     virtual ~THelpTopic();
  57.  
  58.     void addCrossRef( TCrossRef ref );
  59.     void addParagraph( TParagraph *p );
  60.     void getCrossRef( int i, TPoint& loc, uchar& length, int& ref );
  61.     char *getLine( int line, char *buffer, int buflen );
  62.     int getNumCrossRefs();
  63.     int numLines();
  64.     void setCrossRef( int i, TCrossRef& ref );
  65.     void setNumCrossRefs( int i );
  66.     void setWidth( int aWidth );
  67.  
  68.     TParagraph *paragraphs;
  69.  
  70.     int numRefs;
  71.     TCrossRef *crossRefs;
  72.  
  73. private:
  74.  
  75.     char *wrapText( char *text, int size, int& offset, Boolean wrap, char *lineBuf, int lineBufLen );
  76.     void readParagraphs( ipstream& s );
  77.     void readCrossRefs( ipstream& s );
  78.     void writeParagraphs( opstream& s );
  79.     void writeCrossRefs( opstream& s );
  80.     void disposeParagraphs();
  81.     const char *streamableName() const
  82.         { return name; }
  83.     int width;
  84.     int lastOffset;
  85.     int lastLine;
  86.     TParagraph *lastParagraph;
  87.  
  88. protected:
  89.  
  90.     virtual void write( opstream& );
  91.     virtual void *read( ipstream& );
  92.  
  93. public:
  94.  
  95.     static const char * const name;
  96.     static TStreamable *build();
  97.  
  98. };
  99.  
  100. inline ipstream& operator >> ( ipstream& is, THelpTopic& cl )
  101.     { return is >> (TStreamable&)cl; }
  102. inline ipstream& operator >> ( ipstream& is, THelpTopic*& cl )
  103.     { return is >> (void *&)cl; }
  104.  
  105. inline opstream& operator << ( opstream& os, THelpTopic& cl )
  106.     { return os << (TStreamable&)cl; }
  107. inline opstream& operator << ( opstream& os, THelpTopic* cl )
  108.     { return os << (TStreamable *)cl; }
  109.  
  110.  
  111. // THelpIndex
  112.  
  113. class THelpIndex : public TObject, public TStreamable
  114. {
  115. public:
  116.  
  117.  
  118.     THelpIndex();
  119.     THelpIndex( StreamableInit ) {};
  120.     virtual ~THelpIndex();
  121.  
  122.     long position( int );
  123.     void add( int, long );
  124.  
  125.     ushort size;
  126.     long *index;
  127.  
  128. private:
  129.  
  130.     const char *streamableName() const
  131.         { return name; }
  132.  
  133. protected:
  134.  
  135.     virtual void write( opstream& );
  136.     virtual void *read( ipstream& );
  137.  
  138. public:
  139.  
  140.     static const char * const name;
  141.     static TStreamable *build();
  142.  
  143. };
  144.  
  145. inline ipstream& operator >> ( ipstream& is, THelpIndex& cl )
  146.     { return is >> (TStreamable&)cl; }
  147. inline ipstream& operator >> ( ipstream& is, THelpIndex*& cl )
  148.     { return is >> (void *&)cl; }
  149.  
  150. inline opstream& operator << ( opstream& os, THelpIndex& cl )
  151.     { return os << (TStreamable&)cl; }
  152. inline opstream& operator << ( opstream& os, THelpIndex* cl )
  153.     { return os << (TStreamable *)cl; }
  154.  
  155.  
  156. // THelpFile
  157.  
  158. class THelpFile : public TObject
  159. {
  160.  
  161.     static const char * invalidContext;
  162.  
  163. public:
  164.  
  165.     THelpFile( fpstream& s );
  166.     virtual ~THelpFile();
  167.  
  168.     THelpTopic *getTopic( int );
  169.     THelpTopic *invalidTopic();
  170.     void recordPositionInIndex( int );
  171.     void putTopic( THelpTopic* );
  172.  
  173.     fpstream *stream;
  174.     Boolean modified;
  175.  
  176.     THelpIndex *index;
  177.     long indexPos;
  178. };
  179.  
  180. extern void notAssigned( opstream& s, int value );
  181.  
  182. extern TCrossRefHandler crossRefHandler;
  183.