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 };
43 InsetText(InsetText const &, Buffer *);
47 Inset * Clone() const;
51 void Write(std::ostream &) const;
53 int ascent(Painter &, LyXFont const &) const;
55 int descent(Painter &, LyXFont const &) const;
57 int width(Painter &, LyXFont const & f) const;
59 void draw(Painter & pain, LyXFont const &, int , float &) const;
61 char const * EditMessage() const;
63 void Edit(BufferView *, int, int, unsigned int);
65 void InsetUnlock(BufferView *);
67 bool UnlockInsetInInset(BufferView *, Inset *, bool lr = false);
69 bool UpdateInsetInInset(BufferView *, Inset *);
71 void InsetButtonRelease(BufferView *, int, int, int);
73 void InsetButtonPress(BufferView *, int, int, int);
75 void InsetMotionNotify(BufferView *, int, int, int);
77 void InsetKeyPress(XKeyEvent *);
79 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
81 int Latex(std::ostream &, bool fragile, bool free_spc) const;
83 int Linuxdoc(std::ostream &) const { return 0; }
85 int DocBook(std::ostream &) const { return 0; }
87 void Validate(LaTeXFeatures & features) const;
89 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
91 void GetCursorPos(int & x, int & y) const;
95 void ToggleInsetCursor(BufferView *);
97 bool InsertInset(BufferView *, Inset *);
99 UpdatableInset * GetLockingInset();
101 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
103 void init(Buffer *, InsetText const * ins = 0);
109 void UpdateLocal(BufferView *, bool);
111 void WriteParagraphData(std::ostream &) const;
113 void resetPos(BufferView *, bool setfont=false);
115 void drawSelection(Painter &, int pos, int baseline, float x);
117 void SingleHeight(Painter &, LyXParagraph * par,int pos,
118 int & asc, int & desc) const;
120 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
122 LyXFont GetFont(LyXParagraph * par, int pos) const;
124 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
128 LyXFont current_font;
130 LyXFont real_current_font;
132 mutable int maxWidth;
134 mutable int maxAscent;
136 mutable int maxDescent;
138 mutable int insetWidth;
146 void drawRowSelection(Painter &, int startpos, int endpos, int row,
147 int baseline, float x) const;
149 void drawRowText(Painter &, int startpos, int endpos, int baseline,
152 void computeTextRows(Painter &, float x = 0.0) const;
154 void computeBaselines(int) const;
156 int BeginningOfMainBody(LyXParagraph * par) const;
158 void ShowInsetCursor(BufferView *);
160 void HideInsetCursor(BufferView *);
162 void setPos(BufferView *, int x, int y, bool activate_inset = true);
164 bool moveRight(BufferView *, bool activate_inset = true);
165 bool moveLeft(BufferView *, bool activate_inset = true);
166 bool moveUp(BufferView *, bool activate_inset = true);
167 bool moveDown(BufferView *, bool activate_inset = true);
170 bool copySelection();
171 bool pasteSelection();
173 bool hasSelection() const { return selection_start != selection_end; }
175 void SetCharFont(int pos, LyXFont const & font);
179 /* Private structures and variables */
207 mutable bool init_inset;
209 UpdatableInset * the_locking_inset;
222 typedef std::vector<row_struct> RowList;
224 mutable RowList rows;
225 InsetText & operator = (InsetText const & it) {
227 buffer = it.buffer; // suspect
228 current_font = it.current_font;
229 real_current_font = it.real_current_font;
230 maxWidth = it.maxWidth;
231 maxAscent = it.maxAscent;
232 maxDescent = it.maxDescent;
233 insetWidth = it.insetWidth;
234 inset_pos = it.inset_pos;
235 inset_x = it.inset_x;
236 inset_y = it.inset_y;
237 interline_space = it.interline_space;
238 selection_start = it.selection_start;
239 selection_end = it.selection_end;
245 no_selection = it.no_selection;
246 the_locking_inset = it.the_locking_inset; // suspect