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 Linuxdoc(std::ostream &) const { return 0; }
89 int DocBook(std::ostream &) const { return 0; }
91 void Validate(LaTeXFeatures & features) const;
93 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
95 void GetCursorPos(int & x, int & y) const;
99 void ToggleInsetCursor(BufferView *);
101 bool InsertInset(BufferView *, Inset *);
103 UpdatableInset * GetLockingInset();
105 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
107 void init(Buffer *, InsetText const * ins = 0);
113 void UpdateLocal(BufferView *, bool);
115 void WriteParagraphData(std::ostream &) const;
117 void resetPos(Painter &) const;
119 void drawSelection(Painter &, int pos, int baseline, float x);
121 void SingleHeight(Painter &, LyXParagraph * par,int pos,
122 int & asc, int & desc) const;
124 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
126 LyXFont GetFont(LyXParagraph * par, int pos) const;
128 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
130 virtual int getMaxTextWidth(Painter &, UpdatableInset const *,
135 LyXFont current_font;
137 LyXFont real_current_font;
139 mutable int maxAscent;
141 mutable int maxDescent;
143 mutable int insetWidth;
145 mutable int drawTextXOffset;
146 mutable int drawTextYOffset;
152 void drawRowSelection(Painter &, int startpos, int endpos, int row,
153 int baseline, float x) const;
155 void drawRowText(Painter &, int startpos, int endpos, int baseline,
158 void computeTextRows(Painter &, float x = 0.0) const;
160 void computeBaselines(int) const;
162 int BeginningOfMainBody(LyXParagraph * par) const;
164 void ShowInsetCursor(BufferView *);
166 void HideInsetCursor(BufferView *);
168 void setPos(Painter &, int x, int y) const;
170 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
171 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
172 UpdatableInset::RESULT moveUp(BufferView *);
173 UpdatableInset::RESULT moveDown(BufferView *);
176 bool copySelection();
177 bool pasteSelection();
179 bool hasSelection() const { return selection_start != selection_end; }
181 void SetCharFont(int pos, LyXFont const & font);
185 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
188 /* Private structures and variables */
202 mutable LyXCursor cursor;
204 mutable LyXCursor old_cursor;
212 mutable bool init_inset;
214 UpdatableInset * the_locking_inset;
227 typedef std::vector<row_struct> RowList;
229 mutable RowList rows;
230 InsetText & operator = (InsetText const & it) {
232 buffer = it.buffer; // suspect
233 current_font = it.current_font;
234 real_current_font = it.real_current_font;
235 maxAscent = it.maxAscent;
236 maxDescent = it.maxDescent;
237 insetWidth = it.insetWidth;
238 inset_pos = it.inset_pos;
239 inset_x = it.inset_x;
240 inset_y = it.inset_y;
241 interline_space = it.interline_space;
242 selection_start = it.selection_start;
243 selection_end = it.selection_end;
246 no_selection = it.no_selection;
247 the_locking_inset = it.the_locking_inset; // suspect