#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();
///
Inset * Clone() const;
///
- void Read(LyXLex &);
+ InsetText & operator= (InsetText const & it);
+ ///
+ void clear() const { par->clearContents(); }
///
- void Write(ostream &) const;
+ void Read(Buffer const *, LyXLex &);
+ ///
+ void Write(Buffer const *, std::ostream &) const;
///
int ascent(Painter &, LyXFont const &) const;
///
///
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, LyXFont const &, int , float &) 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 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 *);
///
///
UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
///
- int Latex(ostream &, signed char) const;
-#ifndef USE_OSTREAM_ONLY
- ///
- int Latex(string &, signed char) const;
+ int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
///
- int Linuxdoc(string &) const { return 0; }
+ int Ascii(Buffer const *, std::ostream &) const { return 0; }
///
- int DocBook(string &) const { return 0; }
-#else
+ int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
///
- int Linuxdoc(ostream &) const { return 0; }
- ///
- int DocBook(ostream &) const { return 0; }
-#endif
+ 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();
///
///
UpdatableInset * GetLockingInset();
///
- void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
-
- LyXParagraph * par;
-
-protected:
- ///
- void WriteParagraphData(ostream &) const;
+ UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
///
- void resetPos(BufferView *);
+ void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
///
- void drawSelection(Painter &, int pos, int baseline, float x);
+ int getMaxWidth(Painter &, UpdatableInset const *) const;
///
- void SingleHeight(Painter &, LyXParagraph * par,int pos,
- int & asc, int & desc) const;
+ void init(InsetText const * ins = 0);
///
- int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
+ void WriteParagraphData(Buffer const *, std::ostream &) const;
///
- LyXFont GetFont(LyXParagraph * par, int pos) const;
+ void SetParagraphData(LyXParagraph *);
///
- Buffer * buffer;
+ void SetAutoBreakRows(bool);
///
- LyXFont current_font;
+ void SetDrawFrame(BufferView *, DrawFrame);
///
- LyXFont real_current_font;
+ void SetFrameColor(BufferView *, LColor::color);
///
- mutable int maxWidth;
+// LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
///
- mutable int maxAscent;
+ LyXText * getLyXText(BufferView *) const;
+ void deleteLyXText(BufferView *);
+
+ LyXParagraph * par;
///
- mutable int maxDescent;
+ mutable UpdateCodes need_update;
+
+protected:
///
- mutable int insetWidth;
+ 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;
- ///
- void computeTextRows(Painter &, float x = 0.0) const;
+ typedef std::map<BufferView *, LyXText *> Cache;
///
- void computeBaselines(int) const;
+ typedef Cache::value_type value_type;
///
- int BeginningOfMainBody(LyXParagraph * par) const;
+ int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
///
void ShowInsetCursor(BufferView *);
///
void HideInsetCursor(BufferView *);
///
- void setPos(BufferView *, int x, int y, bool activate_inset = true);
+ UpdatableInset::RESULT moveRight(BufferView *, 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 moveLeft(BufferView *, bool activate_inset = true);
///
- bool hasSelection() const { return selection_start != selection_end; }
+ UpdatableInset::RESULT moveUp(BufferView *);
///
- void SetCharFont(int pos, LyXFont const & font);
+ UpdatableInset::RESULT moveDown(BufferView *);
///
- string getText(int);
-
- /* Private structures and variables */
- ///
- 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;
///
- mutable 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