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 = 2 };
+ enum UpdateCodes {
+ NONE = 0,
+ INIT,
+ FULL,
+ CURSOR_PAR,
+ CURSOR,
+ SELECTION,
+ DRAW_FRAME,
+ CLEAR_FRAME
+ };
+ ///
+ enum DrawFrame {
+ NEVER = 0,
+ LOCKED,
+ ALWAYS
+ };
///
explicit
- InsetText(Buffer *);
+ 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;
///
///
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 *);
///
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(std::ostream &) const { return 0; }
+ 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();
///
///
void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
///
- void init(Buffer *, InsetText const * ins = 0);
+ int getMaxWidth(Painter &, UpdatableInset const *) const;
+ ///
+ void init(InsetText const * ins = 0);
+ ///
+ void WriteParagraphData(Buffer const *, std::ostream &) const;
///
void SetParagraphData(LyXParagraph *);
///
void SetAutoBreakRows(bool);
///
- void SetDrawLockedFrame(bool);
+ void SetDrawFrame(BufferView *, DrawFrame);
+ ///
+ void SetFrameColor(BufferView *, LColor::color);
///
- void SetFrameColor(LColor::color);
+// LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
///
- void computeTextRows(Painter &) const;
+ LyXText * getLyXText(BufferView *) const;
+ void deleteLyXText(BufferView *);
LyXParagraph * par;
+ ///
+ mutable UpdateCodes need_update;
protected:
///
- void UpdateLocal(BufferView *, bool);
- ///
- void WriteParagraphData(std::ostream &) const;
- ///
- void resetPos(Painter &) const;
- ///
- void drawSelection(Painter &, int pos, int baseline, float x);
- ///
- void SingleHeight(Painter &, LyXParagraph * par,int pos,
- int & asc, int & desc) const;
- ///
- int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
- ///
- LyXFont GetFont(LyXParagraph * par, int pos) const;
- ///
- virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
- ///
- virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
+ void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
- Buffer * buffer;
- ///
- LyXFont current_font;
- ///
- LyXFont real_current_font;
- ///
- mutable int maxAscent;
- ///
- mutable int maxDescent;
- ///
- mutable int insetWidth;
- ///
mutable int drawTextXOffset;
mutable int drawTextYOffset;
///
bool autoBreakRows;
- bool drawLockedFrame;
+ DrawFrame drawFrame;
///
LColor::color frame_color;
private:
///
- void drawRowSelection(Painter &, int startpos, int endpos, int row,
- int baseline, float x) const;
+ typedef std::map<BufferView *, LyXText *> Cache;
///
- void drawRowText(Painter &, int startpos, int endpos, int baseline,
- float x) 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_cursor != selection_end_cursor); }
+ 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 */
///
- bool locked;
+ 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;
///
///
int interline_space;
///
- LyXCursor selection_start_cursor;
- ///
- LyXCursor selection_end_cursor;
- ///
- 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_cursor = selection_end_cursor = 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