]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.h
Some more changes for updating text-insets.
[lyx.git] / src / insets / insettext.h
index e05c4b0d108afc7ca88c3fe0a176fabc79b8bd9c..223b34ede153db528872a1d1681847b569954042 100644 (file)
 
 #include "lyxinset.h"
 #include "LString.h"
-#include "lyxparagraph.h"
 #include "lyxcursor.h"
 
 class Painter;
 class BufferView;
 class Buffer;
+class LyXCursor;
+class LyXParagraph;
+class LColor;
+class LyXText;
+class LyXScreen;
 
-/** A text inset is like a TeX box
-  
-  To write full text (including styles and other insets) in a given
-  space. 
-*/
+/**
+ * A text inset is like a TeX box to write full text
+ * (including styles and other insets) in a given space. 
+ */
 class InsetText : public UpdatableInset {
 public:
-       ///
-       enum { TEXT_TO_INSET_OFFSET = 1 };
     ///
-       explicit
-    InsetText(Buffer *);
+    enum UpdateCodes {
+       NONE = 0,
+       INIT,
+       FULL,
+       CURSOR_PAR,
+       CURSOR,
+       SELECTION,
+       DRAW_FRAME,
+       CLEAR_FRAME
+    };
+    ///
+    enum DrawFrame {
+       NEVER = 0,
+       LOCKED,
+       ALWAYS
+    };
+    ///
+    explicit
+    InsetText();
     ///
-    InsetText(InsetText const &, Buffer *);
+    InsetText(InsetText const &);
     ///
     ~InsetText();
     ///
     Inset * Clone() const;
     ///
+    InsetText & operator= (InsetText const & it);
+    ///
     void clear() const { par->clearContents(); }
     ///
-    void Read(LyXLex &);
+    void Read(Buffer const *, LyXLex &);
     ///
-    void Write(std::ostream &) const;
+    void Write(Buffer const *, std::ostream &) const;
     ///
     int ascent(Painter &, LyXFont const &) const;
     ///
@@ -58,12 +78,20 @@ public:
     ///
     int width(Painter &, LyXFont const & f) const;
     ///
-    void draw(Painter & pain, LyXFont const &, int , float &) const;
+    int textWidth(Painter &) const;
+    ///
+    void draw(BufferView *, LyXFont const &, int , float &, bool) const;
+    ///
+    void update(BufferView *, LyXFont const &, bool =false);
     ///
     char const * EditMessage() const;
     ///
     void Edit(BufferView *, int, int, unsigned int);
     ///
+    bool IsTextInset() const { return true; }
+    ///
+    bool doClearArea() const { return !locked; }
+    ///
     void InsetUnlock(BufferView *);
     ///
     bool LockInsetInInset(BufferView *, UpdatableInset *);
@@ -82,17 +110,19 @@ public:
     ///
     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
     ///
-    int Latex(std::ostream &, bool fragile, bool free_spc) const;
+    int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
+    ///
+    int Ascii(Buffer const *, std::ostream &) const { return 0; }
     ///
-    int Linuxdoc(std::ostream &) const { return 0; }
+    int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
     ///
-    int DocBook(std::ostream &) const { return 0; }
+    int DocBook(Buffer const *, std::ostream &) const { return 0; }
     ///
     void Validate(LaTeXFeatures & features) const;
     ///
     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
     ///
-    void GetCursorPos(int & x, int & y) const;
+    void GetCursorPos(BufferView *, int & x, int & y) const;
     ///
     int InsetInInsetY();
     ///
@@ -102,91 +132,97 @@ public:
     ///
     UpdatableInset * GetLockingInset();
     ///
-    void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+    UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
     ///
-    void init(Buffer *, InsetText const * ins = 0);
-
-    LyXParagraph * par;
-
-protected:
+    void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
     ///
-    void UpdateLocal(BufferView *, bool);
+    int getMaxWidth(Painter &, UpdatableInset const *) const;
     ///
-    void WriteParagraphData(std::ostream &) const;
+    void init(InsetText const * ins = 0);
     ///
-    void resetPos(Painter &) const;
+    void WriteParagraphData(Buffer const *, std::ostream &) const;
     ///
-    void drawSelection(Painter &, int pos, int baseline, float x);
+    void SetParagraphData(LyXParagraph *);
     ///
-    void SingleHeight(Painter &, LyXParagraph * par,int pos,
-                     int & asc, int & desc) const;
+    void SetAutoBreakRows(bool);
     ///
-    int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
+    void SetDrawFrame(BufferView *, DrawFrame);
     ///
-    LyXFont GetFont(LyXParagraph * par, int pos) const;
+    void SetFrameColor(BufferView *, LColor::color);
     ///
-    virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
+//    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
     ///
-    virtual int getMaxTextWidth(Painter &, UpdatableInset const *,
-                               int x=0) const;
+    LyXText * getLyXText(BufferView *) const;
+    void deleteLyXText(BufferView *);
 
-    Buffer * buffer;
-    ///
-    LyXFont current_font;
-    ///
-    LyXFont real_current_font;
-    ///
-    mutable int maxAscent;
-    ///
-    mutable int maxDescent;
+    LyXParagraph * par;
     ///
-    mutable int insetWidth;
+    mutable UpdateCodes need_update;
+
+protected:
     ///
+    void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
+
     mutable int drawTextXOffset;
     mutable int drawTextYOffset;
     ///
     bool autoBreakRows;
+    DrawFrame drawFrame;
+    ///
+    LColor::color frame_color;
 
 private:
     ///
-    void drawRowSelection(Painter &, int startpos, int endpos, int row,
-                         int baseline, float x) const;
-    ///
-    void drawRowText(Painter &, int startpos, int endpos, int baseline,
-                     float x) const;
+    typedef std::map<BufferView *, LyXText *> Cache;
     ///
-    void computeTextRows(Painter &, float x = 0.0) const;
+    typedef Cache::value_type value_type;
     ///
-    void computeBaselines(int) const;
-    ///
-    int BeginningOfMainBody(LyXParagraph * par) const;
+    int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
     ///
     void ShowInsetCursor(BufferView *);
     ///
     void HideInsetCursor(BufferView *);
     ///
-    void setPos(Painter &, int x, int y) const;
-    ///
     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
+    ///
     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
+    ///
     UpdatableInset::RESULT moveUp(BufferView *);
-    UpdatableInset::RESULT moveDown(BufferView *);
-    bool Delete();
-    bool cutSelection();
-    bool copySelection();
-    bool pasteSelection();
     ///
-    bool hasSelection() const { return selection_start != selection_end; }
+    UpdatableInset::RESULT moveDown(BufferView *);
     ///
-    void SetCharFont(int pos, LyXFont const & font);
+    void SetCharFont(Buffer const *, int pos, LyXFont const & font);
     ///
     string getText(int);
     ///
+    bool checkAndActivateInset(BufferView * bv, bool behind);
     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
                               int button = 0);
+    ///
+    int cx(BufferView *) const;
+    int cy(BufferView *) const;
+    int cpos(BufferView *) const;
+    LyXParagraph * cpar(BufferView *) const;
+    Row * crow(BufferView *) const;
+
+    /// This instead of a macro
+    LyXText * TEXT(BufferView * bv) const {
+       return getLyXText(bv);
+    }
        
     /* Private structures and variables */
     ///
+    mutable bool locked;
+    ///
+    int insetAscent;
+    int insetDescent;
+    int insetWidth;
+    mutable int last_width;
+    mutable int last_height;
+    mutable int top_y;
+    ///
+    LyXParagraph * inset_par;
+    ///
     int inset_pos;
     ///
     mutable int inset_x;
@@ -195,58 +231,14 @@ private:
     ///
     int interline_space;
     ///
-    int selection_start;
-    ///
-    int selection_end;
-    ///
-    mutable LyXCursor cursor;
-    ///
-    mutable LyXCursor old_cursor;
-    ///
-    mutable int actrow;
-    ///
     bool no_selection;
     ///
     mutable float xpos;
     ///
-    mutable bool init_inset;
-    ///
     UpdatableInset * the_locking_inset;
     ///
-    struct row_struct {
-       ///
-       int asc;
-       ///
-       int desc;
-       ///
-       int pos;
-       ///
-       int baseline;
-    };
-    ///
-    typedef std::vector<row_struct> RowList;
-    ///
-    mutable RowList rows;
-    InsetText & operator = (InsetText const & it) {
-       par = it.par;
-       buffer = it.buffer; // suspect
-       current_font = it.current_font;
-       real_current_font = it.real_current_font;
-       maxAscent = it.maxAscent;
-       maxDescent = it.maxDescent;
-       insetWidth = it.insetWidth;
-       inset_pos = it.inset_pos;
-       inset_x = it.inset_x;
-       inset_y = it.inset_y;
-       interline_space = it.interline_space;
-       selection_start = it.selection_start;
-       selection_end = it.selection_end;
-       cursor = it.cursor;
-       actrow = it.actrow;
-       no_selection = it.no_selection;
-       the_locking_inset = it.the_locking_inset; // suspect
-       rows = it.rows;
-       return * this;
-    }
+    LyXParagraph * old_par;
+    /// The cache.
+    mutable Cache cache;
 };
 #endif