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
22 #include "lyxparagraph.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 };
42 InsetText(InsetText const &, Buffer *);
46 Inset * Clone() const;
50 void Write(std::ostream &) const;
52 int ascent(Painter &, LyXFont const &) const;
54 int descent(Painter &, LyXFont const &) const;
56 int width(Painter &, LyXFont const & f) const;
58 void draw(Painter & pain, LyXFont const &, int , float &) const;
60 char const * EditMessage() const;
62 void Edit(BufferView *, int, int, unsigned int);
64 void InsetUnlock(BufferView *);
66 bool UnlockInsetInInset(BufferView *, Inset *, bool lr = false);
68 bool UpdateInsetInInset(BufferView *, Inset *);
70 void InsetButtonRelease(BufferView *, int, int, int);
72 void InsetButtonPress(BufferView *, int, int, int);
74 void InsetMotionNotify(BufferView *, int, int, int);
76 void InsetKeyPress(XKeyEvent *);
78 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
80 int Latex(std::ostream &, signed char, bool free_spc) const;
82 int Linuxdoc(std::ostream &) const { return 0; }
84 int DocBook(std::ostream &) const { return 0; }
86 void Validate(LaTeXFeatures & features) const;
88 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
90 void GetCursorPos(int & x, int & y) const;
94 void ToggleInsetCursor(BufferView *);
96 bool InsertInset(BufferView *, Inset *);
98 UpdatableInset * GetLockingInset();
100 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
102 void init(Buffer *, LyXParagraph * p = 0);
108 void UpdateLocal(BufferView *, bool);
110 void WriteParagraphData(std::ostream &) const;
112 void resetPos(BufferView *);
114 void drawSelection(Painter &, int pos, int baseline, float x);
116 void SingleHeight(Painter &, LyXParagraph * par,int pos,
117 int & asc, int & desc) const;
119 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
121 LyXFont GetFont(LyXParagraph * par, int pos) const;
125 LyXFont current_font;
127 LyXFont real_current_font;
129 mutable int maxWidth;
131 mutable int maxAscent;
133 mutable int maxDescent;
135 mutable int insetWidth;
143 void drawRowSelection(Painter &, int startpos, int endpos, int row,
144 int baseline, float x) const;
146 void drawRowText(Painter &, int startpos, int endpos, int baseline,
149 void computeTextRows(Painter &, float x = 0.0) const;
151 void computeBaselines(int) const;
153 int BeginningOfMainBody(LyXParagraph * par) const;
155 void ShowInsetCursor(BufferView *);
157 void HideInsetCursor(BufferView *);
159 void setPos(BufferView *, int x, int y, bool activate_inset = true);
161 bool moveRight(BufferView *, bool activate_inset = true);
162 bool moveLeft(BufferView *, bool activate_inset = true);
163 bool moveUp(BufferView *, bool activate_inset = true);
164 bool moveDown(BufferView *, bool activate_inset = true);
167 bool copySelection();
168 bool pasteSelection();
170 bool hasSelection() const { return selection_start != selection_end; }
172 void SetCharFont(int pos, LyXFont const & font);
176 /* Private structures and variables */
204 mutable bool init_inset;
206 UpdatableInset * the_locking_inset;
219 typedef std::vector<row_struct> RowList;
221 mutable RowList rows;
222 InsetText & operator = (InsetText const & it) {
224 buffer = it.buffer; // suspect
225 current_font = it.current_font;
226 real_current_font = it.real_current_font;
227 maxWidth = it.maxWidth;
228 maxAscent = it.maxAscent;
229 maxDescent = it.maxDescent;
230 insetWidth = it.insetWidth;
231 inset_pos = it.inset_pos;
232 inset_x = it.inset_x;
233 inset_y = it.inset_y;
234 interline_space = it.interline_space;
235 selection_start = it.selection_start;
236 selection_end = it.selection_end;
242 no_selection = it.no_selection;
243 the_locking_inset = it.the_locking_inset; // suspect