2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 *======================================================
11 // The pristine updatable inset: Text
23 #include "lyxparagraph.h"
24 #include "lyxcursor.h"
30 /** A text inset is like a TeX box
32 To write full text (including styles and other insets) in a given
35 class InsetText : public UpdatableInset {
38 enum { TEXT_TO_INSET_OFFSET = 1 };
43 InsetText(InsetText const &, Buffer *);
47 Inset * Clone() const;
49 void clear() const { par->clearContents(); }
53 void Write(std::ostream &) const;
55 int ascent(Painter &, LyXFont const &) const;
57 int descent(Painter &, LyXFont const &) const;
59 int width(Painter &, LyXFont const & f) const;
61 void draw(Painter & pain, LyXFont const &, int , float &) const;
63 char const * EditMessage() const;
65 void Edit(BufferView *, int, int, unsigned int);
67 void InsetUnlock(BufferView *);
69 bool LockInsetInInset(BufferView *, UpdatableInset *);
71 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
73 bool UpdateInsetInInset(BufferView *, Inset *);
75 void InsetButtonRelease(BufferView *, int, int, int);
77 void InsetButtonPress(BufferView *, int, int, int);
79 void InsetMotionNotify(BufferView *, int, int, int);
81 void InsetKeyPress(XKeyEvent *);
83 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
85 int Latex(std::ostream &, bool fragile, bool free_spc) const;
87 int Ascii(std::ostream &) const { return 0; }
89 int Linuxdoc(std::ostream &) const { return 0; }
91 int DocBook(std::ostream &) const { return 0; }
93 void Validate(LaTeXFeatures & features) const;
95 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
97 void GetCursorPos(int & x, int & y) const;
101 void ToggleInsetCursor(BufferView *);
103 bool InsertInset(BufferView *, Inset *);
105 UpdatableInset * GetLockingInset();
107 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
109 void init(Buffer *, InsetText const * ins = 0);
115 void UpdateLocal(BufferView *, bool);
117 void WriteParagraphData(std::ostream &) const;
119 void resetPos(Painter &) const;
121 void drawSelection(Painter &, int pos, int baseline, float x);
123 void SingleHeight(Painter &, LyXParagraph * par,int pos,
124 int & asc, int & desc) const;
126 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
128 LyXFont GetFont(LyXParagraph * par, int pos) const;
130 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
132 virtual int getMaxTextWidth(Painter &, UpdatableInset const *,
137 LyXFont current_font;
139 LyXFont real_current_font;
141 mutable int maxAscent;
143 mutable int maxDescent;
145 mutable int insetWidth;
147 mutable int drawTextXOffset;
148 mutable int drawTextYOffset;
154 void drawRowSelection(Painter &, int startpos, int endpos, int row,
155 int baseline, float x) const;
157 void drawRowText(Painter &, int startpos, int endpos, int baseline,
160 void computeTextRows(Painter &, float x = 0.0) const;
162 void computeBaselines(int) const;
164 int BeginningOfMainBody(LyXParagraph * par) const;
166 void ShowInsetCursor(BufferView *);
168 void HideInsetCursor(BufferView *);
170 void setPos(Painter &, int x, int y) const;
172 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
173 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
174 UpdatableInset::RESULT moveUp(BufferView *);
175 UpdatableInset::RESULT moveDown(BufferView *);
178 bool copySelection();
179 bool pasteSelection();
181 bool hasSelection() const { return selection_start != selection_end; }
183 void SetCharFont(int pos, LyXFont const & font);
187 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
190 /* Private structures and variables */
204 mutable LyXCursor cursor;
206 mutable LyXCursor old_cursor;
214 mutable bool init_inset;
216 UpdatableInset * the_locking_inset;
229 typedef std::vector<row_struct> RowList;
231 mutable RowList rows;
232 InsetText & operator = (InsetText const & it) {
234 buffer = it.buffer; // suspect
235 current_font = it.current_font;
236 real_current_font = it.real_current_font;
237 maxAscent = it.maxAscent;
238 maxDescent = it.maxDescent;
239 insetWidth = it.insetWidth;
240 inset_pos = it.inset_pos;
241 inset_x = it.inset_x;
242 inset_y = it.inset_y;
243 interline_space = it.interline_space;
244 selection_start = it.selection_start;
245 selection_end = it.selection_end;
248 no_selection = it.no_selection;
249 the_locking_inset = it.the_locking_inset; // suspect