]> 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 b7adc791d270a905767b4fca5549e211f7239f49..223b34ede153db528872a1d1681847b569954042 100644 (file)
@@ -4,7 +4,7 @@
  * 
  *           LyX, The Document Processor
  *
- *           Copyright (C) 1998 The LyX Team.
+ *           Copyright 1998 The LyX Team.
  *
  *======================================================
  */
 #endif
 
 #include "lyxinset.h"
-#include "lyxparagraph.h"
 #include "LString.h"
-#include "buffer.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 };
     ///
-    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();
     ///
-    InsetText * Clone() const;
+    Inset * Clone() const;
     ///
-    void Read(LyXLex &);
+    InsetText & operator= (InsetText const & it);
     ///
-    void Write(ostream &) const;
+    void clear() const { par->clearContents(); }
+    ///
+    void Read(Buffer const *, LyXLex &);
+    ///
+    void Write(Buffer const *, std::ostream &) const;
     ///
     int ascent(Painter &, LyXFont const &) const;
     ///
@@ -54,19 +78,25 @@ public:
     ///
     int width(Painter &, LyXFont const & f) const;
     ///
-    int getMaxWidth(UpdatableInset *) const;
+    int textWidth(Painter &) const;
+    ///
+    void draw(BufferView *, LyXFont const &, int , float &, bool) const;
     ///
-    void draw(Painter & pain, const LyXFont &, int , float &) const;
+    void update(BufferView *, LyXFont const &, bool =false);
     ///
-    const char * EditMessage() const;
+    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 UnlockInsetInInset(BufferView *, Inset *, bool lr=false);
+    bool LockInsetInInset(BufferView *, UpdatableInset *);
     ///
-    //void UpdateLocal(bool flag=true);
+    bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
     ///
     bool UpdateInsetInInset(BufferView *, Inset *);
     ///
@@ -78,21 +108,21 @@ public:
     ///
     void InsetKeyPress(XKeyEvent *);
     ///
-    UpdatableInset::RESULT LocalDispatch(BufferView *, int, string);
+    UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
     ///
-    int Latex(ostream &, signed char) const;
+    int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
     ///
-    int Latex(string &, signed char) const;
+    int Ascii(Buffer const *, std::ostream &) const { return 0; }
     ///
-    int Linuxdoc(class string &) const { return true; }
+    int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
     ///
-    int DocBook(class string &) const { return true; }
+    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);
+    void GetCursorPos(BufferView *, int & x, int & y) const;
     ///
     int InsetInInsetY();
     ///
@@ -102,141 +132,113 @@ public:
     ///
     UpdatableInset * GetLockingInset();
     ///
+    UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+    ///
     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
     ///
-    void init(BufferView *);
-
-    LyXParagraph * par;
-
-protected:
+    int getMaxWidth(Painter &, UpdatableInset const *) const;
     ///
-    void WriteParagraphData(ostream &) const;
+    void init(InsetText const * ins = 0);
     ///
-    void resetPos(BufferView *);
+    void WriteParagraphData(Buffer const *, std::ostream &) const;
     ///
-    void drawSelection(Painter & pain, int pos, int baseline, float x);
+    void SetParagraphData(LyXParagraph *);
     ///
-    void SingleHeight(BufferView *, LyXParagraph * par,int pos,
-                     int & asc, int & desc);
+    void SetAutoBreakRows(bool);
     ///
-    int SingleWidth(BufferView * bv, LyXParagraph * par, int pos);
+    void SetDrawFrame(BufferView *, DrawFrame);
     ///
-    LyXFont GetFont(LyXParagraph * par, int pos) const;
+    void SetFrameColor(BufferView *, LColor::color);
     ///
-    Buffer * buffer;
+//    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
     ///
-    LyXFont current_font;
-       ///
-        LyXFont real_current_font;
-       ///
-       int maxWidth;
-       ///
-        int maxAscent;
-       ///
-       int maxDescent;
-       ///
-       int insetWidth;
+    LyXText * getLyXText(BufferView *) const;
+    void deleteLyXText(BufferView *);
 
-private:
+    LyXParagraph * par;
+    ///
+    mutable UpdateCodes need_update;
+
+protected:
     ///
-    void drawRowSelection(Painter &, int startpos, int endpos, int row,
-                         int baseline, float x) const;
+    void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
+
+    mutable int drawTextXOffset;
+    mutable int drawTextYOffset;
     ///
-    void drawRowText(Painter &, int startpos, int endpos, int baseline,
-                     float x) const;
+    bool autoBreakRows;
+    DrawFrame drawFrame;
     ///
-    void computeTextRows(BufferView *);
+    LColor::color frame_color;
+
+private:
     ///
-    void computeBaselines(int) const;
+    typedef std::map<BufferView *, LyXText *> Cache;
     ///
-    int BeginningOfMainBody(LyXParagraph * par) const;
+    typedef Cache::value_type value_type;
+    ///
+    int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
     ///
     void ShowInsetCursor(BufferView *);
     ///
     void HideInsetCursor(BufferView *);
     ///
-    void setPos(BufferView *, int x, int y, bool activate_inset=true);
-    ///
-    bool moveRight(BufferView *, bool activate_inset = true);
-    bool moveLeft(BufferView *, bool activate_inset = true);
-    bool moveUp(BufferView *, bool activate_inset = true);
-    bool moveDown(BufferView *, bool activate_inset = true);
-    bool Delete();
+    UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
     ///
-    bool hasSelection() const {return (selection_start != selection_end);}
+    UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
     ///
-    void SetCharFont(int pos, LyXFont font);
+    UpdatableInset::RESULT moveUp(BufferView *);
     ///
-    string getText(int);
-       
-    /* Private structures and variables */
+    UpdatableInset::RESULT moveDown(BufferView *);
     ///
-    int inset_pos;
+    void SetCharFont(Buffer const *, int pos, LyXFont const & font);
     ///
-    int inset_x;
+    string getText(int);
     ///
-    int inset_y;
+    bool checkAndActivateInset(BufferView * bv, bool behind);
+    bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
+                              int button = 0);
     ///
-    int interline_space;
+    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 */
     ///
-    int selection_start;
+    mutable bool locked;
     ///
-    int selection_end;
+    int insetAscent;
+    int insetDescent;
+    int insetWidth;
+    mutable int last_width;
+    mutable int last_height;
+    mutable int top_y;
     ///
-    int old_x;
+    LyXParagraph * inset_par;
     ///
-    int cx;
+    int inset_pos;
     ///
-    int cy;
+    mutable int inset_x;
     ///
-    int actpos;
+    mutable int inset_y;
     ///
-    int actrow;
+    int interline_space;
     ///
     bool no_selection;
     ///
-    bool init_inset;
+    mutable float xpos;
     ///
     UpdatableInset * the_locking_inset;
     ///
-    struct row_struct {
-       ///
-       int asc;
-       ///
-       int desc;
-       ///
-       int pos;
-       ///
-       int baseline;
-    };
-    ///
-    typedef 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;
-       maxWidth = it.maxWidth;
-       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;
-       old_x = it.old_x;
-       cx = it.cx;
-       cy = it.cy;
-       actpos = it.actpos;
-       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