]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtext.h
more cursor dispatch
[lyx.git] / src / lyxtext.h
index 8af10531b39349b7e1f1b68a1c9a0469ccc21d3d..1555db6af0d4a22efba4311f4dcb194debd8c7ad 100644 (file)
 
 #include "bufferview_funcs.h"
 #include "Bidi.h"
-#include "layout.h"
+#include "dispatchresult.h"
 #include "lyxfont.h"
+#include "layout.h"
+#include "lyxlayout_ptr_fwd.h"
 #include "ParagraphList_fwd.h"
 #include "RowList_fwd.h"
-#include "textcursor.h"
 
-#include "insets/inset.h"
+#include <iosfwd>
 
 class Buffer;
 class BufferParams;
 class BufferView;
+class CursorSlice;
 class Dimension;
+class InsetBase;
+class InsetOld_code;
+class FuncRequest;
 class LColor_color;
-class InsetText;
-class LyXCursor;
+class LCursor;
+class LyXTextClass;
 class MetricsInfo;
+class PainterInfo;
 class Paragraph;
 class Row;
 class Spacing;
@@ -39,24 +45,14 @@ class UpdatableInset;
 class VSpace;
 
 
-/**
-  This class used to hold the mapping between buffer paragraphs and
-       screen rows. Nowadays, the Paragraphs take care of their rows
-  themselves and this contains just most of the code for manipulating
-  them and interaction with the Cursor.
-  */
-
-// The inheritance from TextCursor should go. It's just there to ease
-// transition...
-class LyXText : public TextCursor {
-       // Public Functions
+/// This class encapsulates the main text data and operations in LyX
+class LyXText {
 public:
-       /// Constructor
-       LyXText(BufferView *, InsetText *, bool ininset, ParagraphList & plist);
+       /// constructor
+       LyXText(BufferView *, bool ininset);
        ///
        void init(BufferView *);
 
-
        /// update y coordinate cache of all paragraphs
        void updateParPositions();
        ///
@@ -79,19 +75,17 @@ public:
          those paragraphs
          */
        ParagraphList::iterator
-       setLayout(LyXCursor & actual_cursor,
-                 LyXCursor & selection_start,
-                 LyXCursor & selection_end,
+       setLayout(ParagraphList::iterator start,
+                 ParagraphList::iterator end,
                  std::string const & layout);
        ///
        void setLayout(std::string const & layout);
 
-       /**
-        * Increase or decrease the nesting depth of the selected paragraph(s)
-        * if test_only, don't change any depths. Returns whether something
-        * (would have) changed
-        */
-       bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
+       /// Increase or decrease the nesting depth of the selected paragraph(s)
+       void changeDepth(bv_funcs::DEPTH_CHANGE type);
+
+       /// Returns whether something would be changed by changeDepth
+       bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type);
 
        /// get the depth at current cursor position
        int getDepth() const;
@@ -107,7 +101,6 @@ public:
                            ParagraphList::iterator end);
        /// rebreaks the given par
        void redoParagraph(ParagraphList::iterator pit);
-
        /// rebreaks the cursor par
        void redoParagraph();
 
@@ -117,29 +110,27 @@ public:
        ///
        std::string getStringToIndex();
 
-       /** insert a character, moves all the following breaks in the
-         same Paragraph one to the right and make a little rebreak
-         */
+       /// insert a character at cursor position
        void insertChar(char c);
-       ///
-       void insertInset(InsetOld * inset);
+       /// insert an inset at cursor position
+       void insertInset(InsetBase * inset);
 
        /// a full rebreak of the whole text
        void fullRebreak();
        /// compute text metrics
        void metrics(MetricsInfo & mi, Dimension & dim);
+       /// draw text (only used for insets)
+       void draw(PainterInfo & pi, int x, int y) const;
 
-       ///
-       DispatchResult dispatch(FuncRequest const & cmd);
-
+       /// try to handle that request
+       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
+       /// access to out BufferView. This should go...
        BufferView * bv();
-
+       /// access to out BufferView. This should go...
        BufferView * bv() const;
 
-       friend class LyXScreen;
-
        /// returns an iterator pointing to a cursor paragraph
-       ParagraphList::iterator getPar(LyXCursor const & cursor) const;
+       ParagraphList::iterator getPar(CursorSlice const & cursor) const;
        ///
        ParagraphList::iterator getPar(lyx::paroffset_type par) const;
        ///
@@ -162,33 +153,27 @@ public:
        lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
                Row const & row, int & x, bool & boundary) const;
 
-       /// need the selection cursor:
-       void setSelection();
-       ///
-       void clearSelection();
-
-       /// select the word we need depending on word_location
-       void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
+       /** Find the word under \c from in the relative location
+        *  defined by \c word_location.
+        *  @param from return here the start of the word
+        *  @param to return here the end of the word
+        */
+       void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
        /// just selects the word the cursor is in
        void selectWord(lyx::word_location loc);
-       /// returns the inset at cursor (if it exists), 0 otherwise
-       InsetOld * getInset() const;
 
        /// accept selected change
        void acceptChange();
-
        /// reject selected change
        void rejectChange();
 
-       /// re-computes the cached coordinates in the cursor
-       void redoCursor();
        ///
        void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
        /// returns true if par was empty and was removed
        bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
                       bool setfont = true, bool boundary = false);
        ///
-       void setCursor(LyXCursor &, lyx::paroffset_type par,
+       void setCursor(CursorSlice &, lyx::paroffset_type par,
                       lyx::pos_type pos, bool boundary = false);
        ///
        void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
@@ -203,7 +188,9 @@ public:
        ///
        void setCursorFromCoordinates(int x, int y);
        ///
-       void setCursorFromCoordinates(LyXCursor &, int x, int y);
+       void setCursorFromCoordinates(CursorSlice &, int x, int y);
+       ///
+       void edit(LCursor & cur, int x, int y);
        ///
        void cursorUp(bool selecting = false);
        ///
@@ -250,8 +237,8 @@ public:
        /// Change the case of the word at cursor position.
        void changeCase(TextCase action);
 
-       ///
-       void toggleInset();
+       /// returns success
+       bool toggleInset();
        ///
        void cutSelection(bool doclear = true, bool realcut = true);
        ///
@@ -265,8 +252,6 @@ public:
         settings are given to the new one.
         */
        void setParagraph(
-                         VSpace const & space_top,
-                         VSpace const & space_bottom,
                          Spacing const & spacing,
                          LyXAlignment align,
                          std::string const & labelwidthstring,
@@ -279,7 +264,6 @@ public:
         * characters to the right. No safety checks.
         */
        void setSelectionRange(lyx::pos_type length);
-
        /** simple replacing. The font of the first selected character
          is used
          */
@@ -291,13 +275,13 @@ public:
        void insertStringAsParagraphs(std::string const & str);
 
        /// Find next inset of some specified type.
-       bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
+       bool gotoNextInset(std::vector<InsetOld_code> const & codes,
                           std::string const & contents = std::string());
        ///
-       void gotoInset(std::vector<InsetOld::Code> const & codes,
+       void gotoInset(std::vector<InsetOld_code> const & codes,
                       bool same_content);
        ///
-       void gotoInset(InsetOld::Code code, bool same_content);
+       void gotoInset(InsetOld_code code, bool same_content);
 
        /// current max text width
        int textWidth() const;
@@ -305,7 +289,7 @@ public:
        /// updates all counters
        void updateCounters();
        /// Returns an inset if inset was hit, or 0 if not.
-       InsetOld * checkInsetHit(int x, int y);
+       InsetBase * checkInsetHit(int x, int y);
 
        ///
        int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
@@ -331,20 +315,10 @@ public:
         * the cursor and when creating a visible row */
        void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
 
-       //
-       // special owner functions
-       ///
-       ParagraphList & ownerParagraphs() const;
-
+       /// access to our paragraphs
+       ParagraphList & paragraphs() const;
        /// return true if this is owned by an inset.
        bool isInInset() const;
-
-       ///
-       ParagraphList::iterator firstPar() const;
-       ///
-       ParagraphList::iterator lastPar() const;
-       ///
-       ParagraphList::iterator endPar() const;
        
        /// return first row of text
        RowList::iterator firstRow() const;
@@ -369,9 +343,9 @@ public:
        ///
        double spacing(Paragraph const &) const;
        ///
-       void cursorLeftOneWord(LyXCursor &);
+       void cursorLeftOneWord(CursorSlice &);
        ///
-       void cursorRightOneWord(LyXCursor &);
+       void cursorRightOneWord(CursorSlice &);
 
        ///
        DispatchResult moveRight();
@@ -390,6 +364,26 @@ public:
        ///
        bool checkAndActivateInset(bool front);
 
+       ///
+       void write(Buffer const & buf, std::ostream & os) const;
+       /// returns whether we've seen our usual 'end' marker
+       bool read(Buffer const & buf, LyXLex & lex);
+
+       ///
+       int ascent() const;
+       ///
+       int descent() const;
+       ///
+       int cursorX(CursorSlice const & cursor) const;
+       ///
+       int cursorY(CursorSlice const & cursor) const;
+
+       /// the current cursor slice
+       CursorSlice & cursor();
+       /// the current cursor slice
+       CursorSlice const & cursor() const;
+
+       friend class LyXScreen;
 
 public:
        ///
@@ -405,7 +399,7 @@ public:
        /// our buffer's default layout font
        LyXFont defaultfont_;
        ///
-       InsetText * inset_owner;
+       int background_color_;
 
        /// only the top-level LyXText has this non-zero
        BufferView * bv_owner;
@@ -415,20 +409,23 @@ public:
        ///
        bool in_inset_;
        ///
-       ParagraphList paragraphs_;
+       ParagraphList paragraphs_;
 
        /// absolute document pixel coordinates of this LyXText
-       int xo_;
-       int yo_;
+       mutable int xo_;
+       mutable int yo_;
+
+       /// our 'outermost' Font
+       LyXFont font_;
 
 
 private:
+       /// return past-the-last paragraph influenced by a layout
+       /// change on pit
+       ParagraphList::iterator undoSpan(ParagraphList::iterator pit);
+       
        /// rebreaks the given par
        void redoParagraphInternal(ParagraphList::iterator pit);
-
-       ///
-       float getCursorX(ParagraphList::iterator pit,
-            Row const & row, lyx::pos_type pos, bool boundary) const;
        /// used in setlayout
        void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
 
@@ -437,10 +434,10 @@ private:
 
        // fix the cursor `cur' after a characters has been deleted at `where'
        // position. Called by deleteEmptyParagraphMechanism
-       void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
+       void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
 
        /// delete double space (false) or empty paragraphs (true) around old_cursor
-       bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
+       bool deleteEmptyParagraphMechanism(CursorSlice const & old_cursor);
 
        ///
        void setCounter(Buffer const &, ParagraphList::iterator pit);
@@ -454,16 +451,10 @@ private:
        /// sets row.end to the pos value *after* which a row should break.
        /// for example, the pos after which isNewLine(pos) == true
        void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
-
        /// sets row.witdh to the minimum space a row needs on the screen in pixel
        void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
-
-       /**
-        * returns the minimum space a manual label needs on the
-        * screen in pixels
-        */
+       /// the minimum space a manual label needs on the screen in pixels
        int labelFill(ParagraphList::iterator pit, Row const & row) const;
-
        /// FIXME
        int labelEnd(ParagraphList::iterator pit) const;
 
@@ -476,6 +467,10 @@ private:
 };
 
 /// return the default height of a row in pixels, considering font zoom
-extern int defaultRowHeight();
+int defaultRowHeight();
+
+///
+std::string expandLabel(LyXTextClass const & textclass,
+               LyXLayout_ptr const & layout, bool appendix);
 
 #endif // LYXTEXT_H