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(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(ostream &, signed char, bool free_spc) const;
81 #ifndef USE_OSTREAM_ONLY
83 int Latex(string &, signed char, bool free_spc) const;
85 int Linuxdoc(string &) const { return 0; }
87 int DocBook(string &) const { return 0; }
90 int Linuxdoc(ostream &) const { return 0; }
92 int DocBook(ostream &) const { return 0; }
95 void Validate(LaTeXFeatures & features) const;
97 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
99 void GetCursorPos(int & x, int & y) const;
103 void ToggleInsetCursor(BufferView *);
105 bool InsertInset(BufferView *, Inset *);
107 UpdatableInset * GetLockingInset();
109 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
115 void UpdateLocal(BufferView *, bool);
117 void WriteParagraphData(ostream &) const;
119 void resetPos(BufferView *);
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;
132 LyXFont current_font;
134 LyXFont real_current_font;
136 mutable int maxWidth;
138 mutable int maxAscent;
140 mutable int maxDescent;
142 mutable int insetWidth;
150 void drawRowSelection(Painter &, int startpos, int endpos, int row,
151 int baseline, float x) const;
153 void drawRowText(Painter &, int startpos, int endpos, int baseline,
156 void computeTextRows(Painter &, float x = 0.0) const;
158 void computeBaselines(int) const;
160 int BeginningOfMainBody(LyXParagraph * par) const;
162 void ShowInsetCursor(BufferView *);
164 void HideInsetCursor(BufferView *);
166 void setPos(BufferView *, int x, int y, bool activate_inset = true);
168 bool moveRight(BufferView *, bool activate_inset = true);
169 bool moveLeft(BufferView *, bool activate_inset = true);
170 bool moveUp(BufferView *, bool activate_inset = true);
171 bool moveDown(BufferView *, bool activate_inset = true);
174 bool hasSelection() const { return selection_start != selection_end; }
176 void SetCharFont(int pos, LyXFont const & font);
180 /* Private structures and variables */
208 mutable bool init_inset;
210 UpdatableInset * the_locking_inset;
223 typedef vector<row_struct> RowList;
225 mutable RowList rows;
226 InsetText & operator = (InsetText const & it) {
228 buffer = it.buffer; // suspect
229 current_font = it.current_font;
230 real_current_font = it.real_current_font;
231 maxWidth = it.maxWidth;
232 maxAscent = it.maxAscent;
233 maxDescent = it.maxDescent;
234 insetWidth = it.insetWidth;
235 inset_pos = it.inset_pos;
236 inset_x = it.inset_x;
237 inset_y = it.inset_y;
238 interline_space = it.interline_space;
239 selection_start = it.selection_start;
240 selection_end = it.selection_end;
246 no_selection = it.no_selection;
247 the_locking_inset = it.the_locking_inset; // suspect