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);
111 void SetParagraphData(LyXParagraph *);
117 void UpdateLocal(BufferView *, bool);
119 void WriteParagraphData(std::ostream &) const;
121 void resetPos(Painter &) const;
123 void drawSelection(Painter &, int pos, int baseline, float x);
125 void SingleHeight(Painter &, LyXParagraph * par,int pos,
126 int & asc, int & desc) const;
128 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
130 LyXFont GetFont(LyXParagraph * par, int pos) const;
132 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
134 virtual int getMaxTextWidth(Painter &, UpdatableInset const *,
139 LyXFont current_font;
141 LyXFont real_current_font;
143 mutable int maxAscent;
145 mutable int maxDescent;
147 mutable int insetWidth;
149 mutable int drawTextXOffset;
150 mutable int drawTextYOffset;
156 void drawRowSelection(Painter &, int startpos, int endpos, int row,
157 int baseline, float x) const;
159 void drawRowText(Painter &, int startpos, int endpos, int baseline,
162 void computeTextRows(Painter &, float x = 0.0) const;
164 void computeBaselines(int) const;
166 int BeginningOfMainBody(LyXParagraph * par) const;
168 void ShowInsetCursor(BufferView *);
170 void HideInsetCursor(BufferView *);
172 void setPos(Painter &, int x, int y) const;
174 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
175 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
176 UpdatableInset::RESULT moveUp(BufferView *);
177 UpdatableInset::RESULT moveDown(BufferView *);
180 bool copySelection();
181 bool pasteSelection();
183 bool hasSelection() const
184 { return (selection_start_cursor != selection_end_cursor); }
186 void SetCharFont(int pos, LyXFont const & font);
190 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
193 /* Private structures and variables */
203 LyXCursor selection_start_cursor;
205 LyXCursor selection_end_cursor;
207 mutable LyXCursor cursor;
209 mutable LyXCursor old_cursor;
217 mutable bool init_inset;
219 UpdatableInset * the_locking_inset;
232 typedef std::vector<row_struct> RowList;
234 mutable RowList rows;
235 InsetText & operator = (InsetText const & it) {
237 buffer = it.buffer; // suspect
238 current_font = it.current_font;
239 real_current_font = it.real_current_font;
240 maxAscent = it.maxAscent;
241 maxDescent = it.maxDescent;
242 insetWidth = it.insetWidth;
243 inset_pos = it.inset_pos;
244 inset_x = it.inset_x;
245 inset_y = it.inset_y;
246 interline_space = it.interline_space;
247 selection_start_cursor = selection_end_cursor = cursor = it.cursor;
249 no_selection = it.no_selection;
250 the_locking_inset = it.the_locking_inset; // suspect