home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / lyxparagraph.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  10KB  |  481 lines

  1. // -*- C++ -*-
  2. /* This file is part of
  3.  * ======================================================
  4.  * 
  5.  *           LyX, The Document Processor
  6.  *      
  7.  *        Copyright (C) 1995 Matthias Ettrich
  8.  *          Copyright (C) 1995-1998 The LyX Team.
  9.  *
  10.  *======================================================*/
  11. #ifndef _LYXPARAGRAPH_H
  12. #define _LYXPARAGRAPH_H
  13.  
  14. #ifdef __GNUG__
  15. #pragma interface
  16. #endif
  17.  
  18. #include "definitions.h"
  19. #include "lyxinset.h"
  20. #include "table.h"
  21. #include "textutils.h"
  22. #include "vspace.h"
  23. #include "insetbib.h"
  24.  
  25. class BufferParams;
  26. class LyXBuffer;
  27. class TexRow;
  28. struct LaTeXFeatures;
  29.  
  30. /// A LyXParagraph holds all text, attributes and insets in a text paragraph
  31. class LyXParagraph  {
  32. public:
  33.  
  34.     /// The footnoteflag
  35.     enum footnote_flag {
  36.         ///
  37.         NO_FOOTNOTE,
  38.         ///
  39.         OPEN_FOOTNOTE,
  40.         ///
  41.         CLOSED_FOOTNOTE
  42.     };
  43.  
  44.     /// The footnotekinds
  45.     enum footnote_kind {
  46.         ///
  47.         FOOTNOTE,
  48.         ///
  49.         MARGIN,
  50.         ///
  51.         FIG,
  52.         ///
  53.         TAB,
  54.         ///
  55.         ALGORITHM,  // Bernhard, 970807
  56.         ///
  57.         WIDE_FIG,   // CFO-G, 971106
  58.         ///
  59.         WIDE_TAB    // CFO-G, 971106
  60.     };
  61.     
  62.     ///
  63.     LyXParagraph();
  64.     /// this konstruktor inserts the new paragraph in a list
  65.     LyXParagraph(LyXParagraph *par);
  66.     /// the destruktors removes the new paragraph from the list
  67.     ~LyXParagraph();
  68.  
  69.     ///
  70.     void writeFile(FILE*, BufferParams &, char, char);
  71.  
  72.     // ///
  73.     //void writeLaTeX(FILE*, BufferParams &);
  74.  
  75.     ///
  76.     void validate(LaTeXFeatures&);
  77.     
  78.     ///
  79.     int GetID(){
  80.         return id;
  81.     }
  82.     ///
  83.     void SetID(int id_arg){
  84.         id = id_arg;
  85.     }
  86.     
  87.     /** allocates more memory for the specified paragraph
  88.       pos is needed to specify the paragraph correctly. Remember the
  89.       closed footnotes
  90.       */
  91.     void Enlarge(int pos, int number);
  92.  
  93.     /** make the allocated memory fit to the needed size
  94.       used to make a paragraph smaller
  95.       */
  96.     void FitSize();
  97.     
  98.     ///
  99.     void read();
  100.     
  101.     ///
  102.     void readSimpleWholeFile(FILE *);
  103.  
  104.     ///
  105.     LyXParagraph* TeXOnePar(LString &file, TexRow &texrow,
  106.                 LString &foot, TexRow &foot_texrow,
  107.                 int &foot_count);
  108.  
  109.     ///
  110.     LyXParagraph* TeXEnvironment(LString &file, TexRow &texrow,
  111.                      LString &foot, TexRow &foot_texrow,
  112.                      int &foot_count);
  113.     
  114.     ///
  115.     LyXParagraph* Clone();
  116.     
  117.     ///
  118.     bool HasSameLayout(LyXParagraph *par);
  119.     
  120.     ///
  121.     void MakeSameLayout(LyXParagraph *par);
  122.  
  123.     /// Is it the first par with same depth and layout?
  124.     bool IsFirstInSequence() {
  125.         LyXParagraph *dhook = DepthHook(GetDepth());
  126.         return (dhook == this
  127.             || dhook->GetLayout() != GetLayout()
  128.             || dhook->GetDepth() != GetDepth());
  129.     }
  130.  
  131.     ///
  132.     int size;
  133.     
  134.     ///
  135.     char *text;
  136.  
  137.     /// 
  138.     VSpace added_space_top;
  139.     
  140.     /// 
  141.     VSpace added_space_bottom;
  142.     
  143.     ///
  144.     signed char layout;
  145.     
  146.     /**
  147.       \begin{itemize}
  148.       \item no footnote, closed footnote, 
  149.       \item open footnote, where footnote
  150.       \item means footnote-environment
  151.       \end{itemize}
  152.      */
  153.     footnote_flag footnoteflag;
  154.  
  155.     /// footnote, margin, fig, tab
  156.     footnote_kind footnotekind;
  157.    
  158.     //@Man: the LyX- DTP-switches
  159.     //@{
  160.     ///
  161.     bool line_top;
  162.     
  163.     ///
  164.     bool line_bottom;
  165.     
  166.       ///
  167.     bool pagebreak_top;
  168.     
  169.     ///
  170.     bool pagebreak_bottom;
  171.     
  172.     ///
  173.     char align;
  174.     
  175.     ///
  176.     char depth;
  177.     
  178.     ///
  179.         bool noindent;
  180.     
  181.     ///
  182.     unsigned char counter[10];
  183.     
  184.     ///
  185.     char enumdepth;
  186.     
  187.     ///
  188.     char itemdepth;
  189.  
  190.         /* This is for the paragraph extra stuff */
  191.         ///
  192.         int pextra_type;
  193.         ///
  194.         LString pextra_width;
  195.         ///
  196.         LString pextra_widthp;
  197.         ///
  198.         int pextra_alignment;
  199.         ///
  200.         bool pextra_hfill;
  201.         ///
  202.         bool pextra_start_minipage;
  203.         
  204.         ///
  205.     LString labelstring;
  206.     
  207.     ///
  208.     LString labelwidthstring;
  209.     //@}
  210.     
  211.     ///
  212.     int last;
  213.     ///
  214.     LyXParagraph *next;
  215.     ///
  216.     LyXParagraph *previous;
  217.  
  218.     /* table stuff -- begin*/
  219.     ///
  220.     LyXTable *table;
  221.     /* table stuff -- end*/
  222.  
  223.         /// 
  224.         InsetBibKey* bibkey;  // ale970302
  225.  
  226.     /** these function are able to hide closed footnotes
  227.      */
  228.     LyXParagraph *Next();
  229.     
  230.     ///
  231.     LyXParagraph *Previous();
  232.  
  233.     /** these function are able to hide open and closed footnotes
  234.      */ 
  235.     LyXParagraph *NextAfterFootnote();
  236.     ///
  237.     LyXParagraph *PreviousBeforeFootnote();
  238.     ///
  239.     LyXParagraph *LastPhysicalPar();
  240.     ///
  241.     LyXParagraph *FirstPhysicalPar();
  242.     
  243.     /// returns the physical paragraph
  244.     LyXParagraph *ParFromPos(int pos);
  245.     /// returns the position in the physical par
  246.     int PositionInParFromPos(int pos);
  247.  
  248.     /// for the environments
  249.     LyXParagraph* DepthHook(int depth);
  250.     ///
  251.     int BeginningOfMainBody();
  252.     ///
  253.     LString GetLabelString();
  254.     
  255.     /// the next two functions are for the manual labels
  256.     LString GetLabelWidthString();
  257.     ///
  258.     void SetLabelWidthString(const LString &s);
  259.     ///
  260.     int GetLayout();
  261.     ///
  262.     char GetAlign();
  263.     ///
  264.     char GetDepth();
  265.     ///
  266.     void SetLayout(char new_layout);
  267.     ///
  268.     void SetOnlyLayout(char new_layout);
  269.     ///
  270.     unsigned char GetCounter(int i);
  271.     ///
  272.     int Last();
  273.     
  274.     /** This one resets all layout and dtp switches but not the font
  275.      of the single characters
  276.      */ 
  277.     void Clear();
  278.     ///
  279.     void Erase(int pos);
  280.  
  281.     /** the flag determines wether the layout should be copied
  282.      */ 
  283.     void BreakParagraph(int pos, int flag);
  284.     ///
  285.     void BreakParagraphConservative(int pos);
  286.  
  287.     /** paste this paragraph with the next one
  288.       be carefull, this doesent make any check at all
  289.       */ 
  290.     void PasteParagraph();
  291.  
  292.     /** Get unistantiated font setting. Returns the difference
  293.       between the characters font and the layoutfont.
  294.       This is what is stored in the fonttable
  295.      */ 
  296.     LyXFont GetFontSettings(int pos);
  297.     
  298.     /** Get fully instantiated font. If pos == -1, use the layout
  299.       font attached to this paragraph.
  300.       If pos == -2, use the label font of the layout attached here.
  301.       In all cases, the font is instantiated, i.e. does not have any
  302.       attributes with values LyXFont::INHERIT, LyXFont::IGNORE or 
  303.       LyXFont::TOGGLE.
  304.       */
  305.     LyXFont getFont(int pos);
  306.     
  307.     ///
  308.     char GetChar(int pos);
  309.     ///
  310.     void SetFont(int pos, LyXFont const & font);
  311.     /// Returns the height of the highest font in range
  312.     LyXFont::FONT_SIZE HighestFontInRange(int startpos, int endpos) const;
  313.     ///
  314.     void InsertChar(int pos, char c);
  315.     ///
  316.     void InsertInset(int pos, Inset *inset);
  317.     ///
  318.     Inset* GetInset(int pos);
  319.     
  320.     /// used to remove the error messages
  321.     int AutoDeleteInsets();
  322.  
  323.     ///
  324.     Inset* ReturnNextInsetPointer(int &pos);
  325.     
  326.     /// returns -1 if inset not found
  327.     int GetPositionOfInset(Inset* inset);
  328.     
  329.     /// ok and now some footnote functions
  330.     void OpenFootnotes();
  331.     ///
  332.     void OpenFootnote(int pos);
  333.     ///
  334.     void CloseFootnotes();
  335.     ///
  336.     void CloseFootnote(int pos);
  337.    
  338.     /// important for cut and paste
  339.     void CopyIntoMinibuffer(int pos);
  340.     ///
  341.     void CutIntoMinibuffer(int pos);
  342.     ///
  343.     void InsertFromMinibuffer(int pos);
  344.     
  345.     ///
  346.     LyXParagraph *FirstSelfrowPar();
  347.     
  348.     ///
  349.     bool IsHfill(int pos) {
  350.         return IsHfillChar(GetChar(pos));
  351.     }
  352.     
  353.     ///
  354.     bool IsInset(int pos) {
  355.         return IsInsetChar(GetChar(pos));
  356.     }
  357.     
  358.     ///
  359.     bool IsFloat(int pos) {
  360.         return IsFloatChar(GetChar(pos));
  361.     }
  362.     
  363.     ///
  364.     bool IsNewline(int pos) {
  365.         bool tmp=false;
  366.         if (pos>=0)
  367.             tmp= IsNewlineChar(GetChar(pos));
  368.         return tmp;
  369.     }
  370.     
  371.     ///
  372.     bool IsSeparator(int pos) {
  373.         return IsSeparatorChar(GetChar(pos));
  374.     }
  375.     
  376.     ///
  377.     bool IsLineSeparator(int pos) {
  378.         return IsLineSeparatorChar(GetChar(pos));
  379.     }
  380.     
  381.     ///
  382.     bool IsKomma(int pos){
  383.         return IsKommaChar(GetChar(pos));
  384.     }
  385.     
  386.     /// Used by the spellchecker
  387.     bool IsLetter(int pos);
  388.     
  389.     ///
  390.     int ClearParagraph(){
  391.         int i=0;
  392.         if (!IsDummy() && !table){
  393.             while (Last()
  394.                    && (IsNewline(0) 
  395.                    || IsLineSeparator(0))){
  396.                 Erase(0);
  397.                 i++;
  398.             }
  399.         }
  400.         return i;
  401.     }
  402.     
  403.     /** A paragraph following a footnote is a "dummy". A paragraph
  404.       with a footnote in it is stored as three paragraphs:
  405.       First a paragraph with the text up to the footnote, then
  406.       one (or more) paragraphs with the footnote, and finally
  407.       the a paragraph with the text after the footnote. Only the
  408.       first paragraph keeps information  about layoutparameters, */
  409.     bool IsDummy(){
  410.         return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
  411.             && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
  412.     }
  413.  
  414.         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
  415.            I have to set it on each of it's elements */
  416.     ///
  417.         void SetPExtraType(int type, const char *width, const char *widthp);
  418.     ///
  419.         void UnsetPExtraType();
  420.     ///
  421.     bool RoffContTableRows(FILE *file, int i, int actcell);
  422. private:
  423.     /** A font entry covers a range of positions. Notice that the
  424.       entries in the list are inserted in random order.
  425.       I don't think it's worth the effort to implement a more effective
  426.       datastructure, because the number of different fonts in a paragraph
  427.       is limited. (Asger)
  428.     */
  429.     struct FontTable  {
  430.         /// Start position of paragraph this font attribute covers
  431.         int pos;
  432.         /// Ending position of paragraph this font attribute covers
  433.         int pos_end;
  434.  
  435.         /** Font. Interpretation of the font values:
  436.         If a value is LyXFont::INHERIT_*, it means that the font 
  437.         attribute is inherited from either the layout of this
  438.         paragraph or, in the case of nested paragraphs, from the 
  439.         layout in the environment one level up until completely 
  440.         resolved.
  441.         The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT 
  442.         allowed in these font tables.
  443.         */
  444.         LyXFont font;
  445.         /// Pointer to next font entry
  446.         FontTable *next;
  447.     };
  448.     ///
  449.     struct InsetTable {
  450.         ///
  451.         int pos;
  452.         ///
  453.         Inset *inset;
  454.         ///
  455.         InsetTable *next;
  456.     };
  457.     ///
  458.     FontTable *fonttable;
  459.     ///
  460.     InsetTable *insettable;
  461.     ///
  462.     LyXParagraph * TeXDeeper(LString &file, TexRow &texrow,
  463.                    LString &foot, TexRow &foot_texrow,
  464.                    int &foot_count);
  465.     ///
  466.     LyXParagraph * TeXFootnote(LString &file, TexRow &texrow,
  467.                    LString &foot, TexRow &foot_texrow,
  468.                    int &foot_count);
  469.     ///
  470.     bool SimpleTeXOnePar(LString &file, TexRow &texrow);
  471.     ///
  472.     bool SimpleTeXOneTablePar(LString &file, TexRow &texrow);
  473.     ///
  474.     bool TeXContTableRows(LString &file, int i, int current_cell_number,
  475.                               int &column, TexRow &texrow);
  476.     ///
  477.     int id;
  478. };
  479.  
  480. #endif
  481.