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 / lyxtext.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  14KB  |  564 lines

  1. // -*- C++ -*-
  2. /* This file is part of
  3.  * ======================================================
  4.  * 
  5.  *           LyX, The Document Processor
  6.  *      
  7.  *        Copyright (C) 1995 Matthias Ettrich
  8.  *
  9.  *======================================================*/
  10.  
  11. #ifndef _LYXTEXT_H
  12. #define _LYXTEXT_H
  13.  
  14. #ifdef __GNUG__
  15. #pragma interface
  16. #endif
  17.  
  18. #include "definitions.h"
  19. #include "layout.h"
  20. #include "lyxfont.h"
  21. #include "lyxrow.h"
  22. #include "undo.h"
  23. #include "lyxcursor.h"
  24.  
  25. class Buffer;
  26. class BufferParams;
  27. class LyXScreen;
  28.  
  29. /**
  30.   This class holds the mapping between buffer paragraphs and screen rows.
  31.   */
  32. class LyXText {
  33. public:
  34.     ///
  35.     enum text_status {
  36.         ///
  37.         UNCHANGED,
  38.         ///
  39.         NEED_LITTLE_REFRESH,
  40.         ///
  41.         NEED_MORE_REFRESH,
  42.         ///
  43.         NEED_VERY_LITTLE_REFRESH
  44.     };
  45.  
  46.     /// points to Buffer.params
  47.     BufferParams *parameters;
  48.     /// points to Buffer
  49.     Buffer *params;
  50.     ///
  51.     int number_of_rows;
  52.     ///
  53.     long height;
  54.     /// the current font settings
  55.     LyXFont current_font;
  56.     /// the current font
  57.     LyXFont real_current_font;
  58.  
  59.     /// Constructor
  60.     LyXText(int paperwidth, Buffer *);
  61.    
  62.     /// Destructor
  63.     ~LyXText();
  64.    
  65.     ///
  66.     LyXFont GetFont(LyXParagraph* par, int pos);
  67.     ///
  68.     void SetCharFont(LyXParagraph *par, int pos, LyXFont font);
  69.    
  70.     /// returns a pointer to the very first LyXParagraph
  71.     LyXParagraph *FirstParagraph();
  72.   
  73.     /// what you expect when pressing <enter> at cursor position
  74.     void BreakParagraph(char keep_layout = 0);
  75.  
  76.     /** set layout over selection and make a total rebreak of
  77.       those paragraphs
  78.       */
  79.     void SetLayout(char layout);
  80.     
  81.     /// used in setlayout
  82.     void MakeFontEntriesLayoutSpecific(LyXParagraph *par);
  83.     
  84.     /** increment depth over selection and make a total rebreak of those 
  85.       paragraphs
  86.       */
  87.     void IncDepth();
  88.     
  89.     /** decrement depth over selection and make a total rebreak of those  
  90.       paragraphs */
  91.     void DecDepth();
  92.  
  93.     /** Get the depth at current cursor position
  94.      */
  95.     int GetDepth() { return cursor.par->GetDepth(); }
  96.     
  97.     /** set font over selection and make a total rebreak of those
  98.       paragraphs.
  99.       */
  100.     void SetFont(LyXFont font);
  101.     
  102.     /** deletes and inserts again all paragaphs between the cursor
  103.       and the specified par .The Cursor is needed to set the refreshing
  104.       parameters. 
  105.       This function is needed after SetLayout and SetFont etc.
  106.       */
  107.     void RedoParagraphs(LyXCursor cursor, LyXParagraph *end_par);
  108.     ///
  109.     void RedoParagraph();
  110.     
  111.     ///
  112.     void ToggleFree(LyXFont font);
  113.     
  114.     /** recalculates the heights of all previous rows of the
  115.         specified paragraph.  needed, if the last characters font
  116.         has changed.  
  117.         */
  118.     void RedoHeightOfParagraph(LyXCursor cursor);
  119.     
  120.     /** forces the redrawing of a paragraph. Needed when manipulating a 
  121.         right address box
  122.         */ 
  123.     void RedoDrawingOfParagraph(LyXCursor cursor);
  124.     
  125.     /** insert a character, moves all the following breaks in the 
  126.       same Paragraph one to the right and make a little rebreak
  127.       */
  128.     void InsertChar(char c);
  129.     ///
  130.     void InsertInset(Inset *inset);
  131.    
  132.     /// completes the insertion with a full rebreak
  133.     int FullRebreak();
  134.    
  135.     /// may be important for the menu
  136.     char* GetLayout(int row);
  137.     ///
  138.     LyXParagraph::footnote_flag GetFootnoteFlag(int row);
  139.     ///
  140.     Row* need_break_row;
  141.     ///
  142.     long refresh_y;
  143.     ///
  144.     int refresh_height;
  145.     ///
  146.     int refresh_width;
  147.     ///
  148.     int refresh_x;
  149.     ///
  150.     Row *refresh_row;
  151.     ///
  152.     int refresh_pos;
  153.     
  154.     /** wether the screen needs a refresh,
  155.        starting with refresh_y
  156.        */
  157.     text_status status;
  158.     
  159.     /** returns a pointer to the row near the specified y-coordinate
  160.       (relative to the whole text). y is set to the real beginning
  161.       of this row
  162.       */ 
  163.     Row* GetRowNearY(long &y);
  164.     
  165.     /** returns the column near the specified x-coordinate of the row 
  166.      x is set to the real beginning of this column
  167.      */ 
  168.     int GetColumnNearX(Row *row, int& x);
  169.     
  170.     /** returns a pointer to a specified row. y is set to the beginning
  171.      of the row
  172.      */
  173.     Row* GetRow(LyXParagraph *par, int pos, long &y);
  174.     
  175.     /** returns the height of a default row, needed  for scrollbar
  176.      */
  177.     int DefaultHeight();
  178.    
  179.     /** The cursor.
  180.       Later this variable has to be removed. There should be now internal
  181.       cursor in a text (and thus not in a buffer). By keeping this it is
  182.       (I think) impossible to have several views with the same buffer, but
  183.       the cursor placed at different places.
  184.       */
  185.     LyXCursor cursor;
  186.    
  187.     /* the selection cursor */
  188.     /// 
  189.     bool selection;
  190.     ///
  191.     bool mark_set;
  192.  
  193.     ///
  194.     LyXCursor sel_cursor;
  195.     ///
  196.     LyXCursor sel_start_cursor;
  197.     ///
  198.     LyXCursor sel_end_cursor;
  199.     /// needed for the toggling
  200.     LyXCursor last_sel_cursor;
  201.     ///
  202.     LyXCursor toggle_cursor;
  203.     ///
  204.     LyXCursor toggle_end_cursor;
  205.    
  206.     /// need the selection cursor:
  207.     void SetSelection();
  208.     ///
  209.     void ClearSelection();
  210.  
  211.     /// just selects the word the cursor is in
  212.     void SelectWord();
  213.  
  214.     /** 'selects" the next word, where the cursor is not in 
  215.      and returns this word as string. THe cursor will be moved 
  216.      to the beginning of this word. 
  217.      With SelectSelectedWord can this be highlighted really
  218.      */ 
  219.     char* SelectNextWord(float &value);
  220.     ///
  221.     void SelectSelectedWord();
  222.     ///
  223.     void SetCursor(LyXParagraph *par, int pos);
  224.     ///
  225.     void SetCursorIntern(LyXParagraph *par, int pos);
  226.     ///
  227.     void SetCursorFromCoordinates(int x, long y);
  228.     ///
  229.     void CursorUp();
  230.     ///
  231.     void CursorDown();
  232.     ///
  233.     void CursorLeft();
  234.     ///
  235.     void CursorRight();
  236.     ///
  237.     void CursorLeftOneWord();
  238.     ///
  239.     void CursorRightOneWord();
  240.     ///
  241.     void CursorUpParagraph();
  242.     ///
  243.     void CursorDownParagraph();
  244.     ///
  245.     void CursorHome();
  246.     ///
  247.     void CursorEnd();
  248.     ///
  249.     void CursorTab();
  250.     ///
  251.     void CursorTop();
  252.     ///
  253.     void CursorBottom();
  254.     ///
  255.     void Delete();
  256.     ///
  257.     void Backspace();
  258.     ///
  259.     void DeleteWordForward();
  260.     ///
  261.     void DeleteWordBackward();
  262.     ///
  263.     void DeleteLineForward();
  264.     ///
  265.     int SelectWordWhenUnderCursor();
  266.     ///
  267.     void UpcaseWord();
  268.     ///
  269.     void LowcaseWord();
  270.     ///
  271.     void CapitalizeWord();
  272.  
  273.     /** returns a printed row in a pixmap. The y value is needed to
  274.       decide, wether it is selected text or not. This is a strange
  275.       solution but faster.
  276.      */ 
  277.     void GetVisibleRow(LyXScreen &scr, int offset, 
  278.                Row *row_ptr, long y);
  279.                        
  280.     /* footnotes: */
  281.     ///
  282.     void ToggleFootnote();
  283.     ///
  284.     void OpenStuff();
  285.     ///
  286.     void OpenFootnotes();
  287.     ///
  288.     void OpenFootnote();
  289.     ///
  290.     void CloseFootnotes();
  291.     ///
  292.     void CloseFootnote();
  293.  
  294.     /** turn the selection into a new environment. If there is no
  295.       selection, create an empty environment
  296.      */ 
  297.     void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
  298.     ///
  299.     void MeltFootnoteEnvironment();
  300.     ///
  301.     void CutSelection(bool = true);
  302.     ///
  303.     void CopySelection();
  304.     ///
  305.     void PasteSelection();
  306.     ///
  307.     void copyEnvironmentType();
  308.     ///
  309.     void pasteEnvironmentType();
  310.     ///
  311.     void InsertFootnote();
  312.     ///
  313.     void InsertMarginpar();
  314.     ///
  315.     void InsertFigure();
  316.     ///
  317.     void InsertTabular();
  318.  
  319.     /** the DTP switches for paragraphs. LyX will store the top settings
  320.      always in the first physical paragraph, the bottom settings in the
  321.      last. When a paragraph is broken, the top settings rest, the bottom 
  322.      settings are given to the new one. So I can make shure, they do not
  323.      duplicate themself (and you cannnot make dirty things with them! )
  324.      */ 
  325.     void SetParagraph(bool line_top, bool line_bottom,
  326.               bool pagebreak_top, bool pagebreak_bottom,
  327.               VSpace space_top, VSpace space_bottom,
  328.               char align, 
  329.               LString labelwidthstring,
  330.               bool noindent);
  331.         void SetParagraphExtraOpt(int type,
  332.                                   const char *width,
  333.                                   const char *widthp,
  334.                                   int alignment, bool hfill,
  335.                                   bool start_minipage);
  336.  
  337.     /* these things are for search and replace */
  338.  
  339.     /** returns true if the specified string is at the specified
  340.       position
  341.       */
  342.     bool IsStringInText(LyXParagraph *par, int pos, char const* string);
  343.  
  344.     /** sets the selection over the number of characters of string,
  345.       no check!!
  346.       */
  347.     void SetSelectionOverString(char const* string);
  348.  
  349.     /** simple replacing. The font of the first selected character
  350.       is used
  351.       */
  352.     void ReplaceSelectionWithString(char const* string);
  353.  
  354.     /** if the string can be found: return true and set the cursor to
  355.       the new position */
  356.     bool SearchForward(char const* string);
  357.     bool SearchBackward(char const* string);
  358.  
  359.     /// needed to insert the selection
  360.     void InsertStringA(char* string);
  361.     /// needed to insert the selection
  362.     void InsertStringB(char* string);
  363.    
  364.     /// usefull when texing from within LyX
  365.     bool GotoNextError();
  366.  
  367.     /// just another feature :)
  368.     bool GotoNextNote();
  369.  
  370.     /** needed to switch between different classes this works
  371.       for a list of paragraphs beginning with the specified par 
  372.       return value is the number of wrong conversions
  373.       */ 
  374.     int SwitchLayoutsBetweenClasses(char class1, char class2, LyXParagraph *par);
  375.  
  376.     /* for the greater insets */
  377.   
  378.     /// returns 0 if inset wasn't found
  379.     int UpdateInset(Inset* inset);
  380.     ///
  381.     void CheckParagraph(LyXParagraph* par, int pos);
  382.  
  383.     /* table stuff -- begin*/
  384.  
  385.     /** all table features of the text-class are put together in
  386.       this function. Possible values of feature are defined in table.h
  387.       */
  388.     void TableFeatures(int feature,LString val);
  389.         ///
  390.     void TableFeatures(int feature);
  391.     ///
  392.     int NumberOfCell(LyXParagraph *par, int pos);
  393.  
  394.     /** pos points at the beginning of the next cell (if there is one)
  395.      */
  396.     int WidthOfCell(LyXParagraph *par, int &pos);
  397.     ///
  398.     void InsertCharInTable(char c);
  399.     ///
  400.     void BackspaceInTable();
  401.     ///
  402.     void CheckParagraphInTable(LyXParagraph* par, int pos);
  403.     ///
  404.     char HitInTable(Row* row, int x);
  405.     ///
  406.     bool MouseHitInTable(int x, long y);
  407.     /* table stuff -- end*/
  408.     ///
  409.     LyXParagraph* GetParFromID(int id);
  410.  
  411.     // undo functions
  412.     /// returns false if no undo possible
  413.     bool  TextUndo();
  414.     /// returns false if no redo possible
  415.     bool  TextRedo();
  416.     /// used by TextUndo/TextRedo
  417.     bool TextHandleUndo(Undo* undo);
  418.     /// makes sure the next operation will be stored
  419.     void FinishUndo();
  420.     /// this is dangerous and for internal use only
  421.     void FreezeUndo();
  422.     /// this is dangerous and for internal use only
  423.     void UnFreezeUndo();
  424.     /// the flag used by FinishUndo();
  425.     bool undo_finished;
  426.     /// a flag
  427.     bool undo_frozen;
  428.     ///
  429.     void SetUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
  430.     ///
  431.     void SetRedo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
  432.     ///
  433.     Undo *CreateUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
  434.     /// for external use in lyx_cb.C
  435.     void SetCursorParUndo();
  436.     ///
  437.     void CursorLeftIntern();
  438.     ///
  439.     void CursorRightIntern();
  440.         ///
  441.         void RemoveTableRow(LyXCursor *cursor);
  442.         ///
  443.         bool IsEmptyTableRow(LyXCursor *cursor);
  444.         ///
  445.         bool IsEmptyTableCell();
  446.  
  447. private:
  448.     ///
  449.     Row* firstrow;
  450.     ///
  451.     Row* lastrow;
  452.  
  453.     /** Copybuffer for copy environment type
  454.       Asger has learned that this should be a buffer-property instead
  455.       Lgb has learned that 'char' is a lousy type for non-characters
  456.       */
  457.     char copylayouttype;
  458.  
  459.     /// the currentrow is needed to access rows faster*/ 
  460.     Row* currentrow;               /* pointer to the current row  */
  461.     /// position in the text 
  462.     long  currentrow_y;
  463.     /// width of the paper
  464.     unsigned short  paperwidth;
  465.    
  466.     /** inserts a new row behind the specified row, increments
  467.      * the touched counters */
  468.     void InsertRow(Row *row, LyXParagraph *par, int pos );
  469.  
  470.     /** removes the row and reset the touched counters */
  471.     void RemoveRow(Row *row);
  472.  
  473.     /** remove all following rows of the paragraph of the specified row. */
  474.     void RemoveParagraph(Row *row);
  475.  
  476.     /** insert the specified paragraph behind the specified row */
  477.     void InsertParagraph(LyXParagraph *par, Row *row);
  478.  
  479.     /** appends  the implizit specified paragraph behind the specified row,
  480.      * start at the implizit given position */
  481.     void AppendParagraph(Row *row);
  482.    
  483.     ///
  484.     void BreakAgain(Row *row);
  485.     ///
  486.     void BreakAgainOneRow(Row *row);
  487.     ///
  488.     void SetHeightOfRow(Row *row_ptr); /* calculate and set the height 
  489.                         * of the row */
  490.  
  491.     /** this calculates the specified parameters. needed when setting
  492.      * the cursor and when creating a visible row */ 
  493.     void PrepareToPrint(Row *row, float &x, float &fill_separator, 
  494.                 float &fill_hfill, float &fill_label_hfill);
  495.     ///
  496.     void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
  497.  
  498.     /** Updates all counters starting BEHIND the row. Changed paragraphs
  499.      * with a dynamic left margin will be rebroken. */ 
  500.     void UpdateCounters(Row *row);
  501.     ///
  502.     void SetCounter(LyXParagraph *par);
  503.    
  504.     /*
  505.      * some low level functions
  506.      */
  507.     
  508.     ///
  509.     int SingleWidth(LyXParagraph *par, int pos);
  510.     ///
  511.     int SingleWidth(LyXParagraph *par, int pos, char c);
  512.     ///
  513.     void Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x);
  514.     /// get the next breakpoint in a given paragraph
  515.     int NextBreakPoint(Row* row, int width);
  516.     /// returns the minimum space a row needs on the screen in pixel
  517.     int Fill(Row *row, int paperwidth);
  518.     
  519.     /** returns the minimum space a manual label needs on the
  520.       screen in pixel */ 
  521.     int LabelFill(Row *row);
  522.     
  523.     ///
  524.     int BeginningOfMainBody(LyXParagraph *par);
  525.     
  526.     /** Returns the left beginning of the text.
  527.       This information cannot be taken from the layouts-objekt, because
  528.       in LaTeX the beginning of the text fits in some cases
  529.       (for example sections) exactly the label-width.
  530.       */
  531.     int LeftMargin(Row *row);
  532.     ///
  533.     int RightMargin(Row *row);
  534.     ///
  535.     int LabelEnd (Row *row);
  536.  
  537.     /** returns the number of separators in the specified row.
  538.       The separator on the very last column doesnt count
  539.       */ 
  540.     int NumberOfSeparators(Row *row);
  541.  
  542.     /** returns the number of hfills in the specified row. The
  543.       LyX-Hfill is a LaTeX \hfill so that the hfills at the
  544.       beginning and at the end were ignored. This is {\em MUCH}
  545.       more usefull than not to ignore!
  546.       */
  547.     int NumberOfHfills(Row *row);
  548.    
  549.     /// like NumberOfHfills, but only those in the manual label!
  550.     int NumberOfLabelHfills(Row *row);
  551.  
  552.     /** returns true, if a expansion is needed. Rules are given by 
  553.       LaTeX
  554.       */ 
  555.     bool HfillExpansion(Row *row_ptr, int pos);
  556.    
  557.     /** returns the paragraph position of the last character in the 
  558.       specified row
  559.       */
  560.     int RowLast(Row *row);
  561. };
  562.  
  563. #endif
  564.