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 "lyxcursor.h"
32 /** A text inset is like a TeX box
34 To write full text (including styles and other insets) in a given
37 class InsetText : public UpdatableInset {
40 enum { TEXT_TO_INSET_OFFSET = 2 };
45 InsetText(InsetText const &, Buffer *);
49 Inset * Clone() const;
51 void clear() const { par->clearContents(); }
55 void Write(std::ostream &) const;
57 int ascent(Painter &, LyXFont const &) const;
59 int descent(Painter &, LyXFont const &) const;
61 int width(Painter &, LyXFont const & f) const;
63 void draw(Painter & pain, LyXFont const &, int , float &) const;
65 char const * EditMessage() const;
67 void Edit(BufferView *, int, int, unsigned int);
69 void InsetUnlock(BufferView *);
71 bool LockInsetInInset(BufferView *, UpdatableInset *);
73 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
75 bool UpdateInsetInInset(BufferView *, Inset *);
77 void InsetButtonRelease(BufferView *, int, int, int);
79 void InsetButtonPress(BufferView *, int, int, int);
81 void InsetMotionNotify(BufferView *, int, int, int);
83 void InsetKeyPress(XKeyEvent *);
85 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
87 int Latex(std::ostream &, bool fragile, bool free_spc) const;
89 int Ascii(std::ostream &) const { return 0; }
91 int Linuxdoc(std::ostream &) const { return 0; }
93 int DocBook(std::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 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
111 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
113 void init(Buffer *, InsetText const * ins = 0);
115 void SetParagraphData(LyXParagraph *);
117 void SetAutoBreakRows(bool);
119 void SetDrawLockedFrame(bool);
121 void SetFrameColor(LColor::color);
123 void computeTextRows(Painter &) const;
129 void UpdateLocal(BufferView *, bool);
131 void WriteParagraphData(std::ostream &) const;
133 void resetPos(Painter &) const;
135 void drawSelection(Painter &, int pos, int baseline, float x);
137 void SingleHeight(Painter &, LyXParagraph * par,int pos,
138 int & asc, int & desc) const;
140 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
142 LyXFont GetFont(LyXParagraph * par, int pos) const;
144 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
146 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
150 LyXFont current_font;
152 LyXFont real_current_font;
154 mutable int maxAscent;
156 mutable int maxDescent;
158 mutable int insetWidth;
160 mutable int drawTextXOffset;
161 mutable int drawTextYOffset;
164 bool drawLockedFrame;
166 LColor::color frame_color;
170 void drawRowSelection(Painter &, int startpos, int endpos, int row,
171 int baseline, float x) const;
173 void drawRowText(Painter &, int startpos, int endpos, int baseline,
176 void computeBaselines(int) const;
178 int BeginningOfMainBody(LyXParagraph * par) const;
180 void ShowInsetCursor(BufferView *);
182 void HideInsetCursor(BufferView *);
184 void setPos(Painter &, int x, int y) const;
186 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
188 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
190 UpdatableInset::RESULT moveUp(BufferView *);
192 UpdatableInset::RESULT moveDown(BufferView *);
198 bool copySelection();
200 bool pasteSelection();
202 bool hasSelection() const
203 { return (selection_start_cursor != selection_end_cursor); }
205 void SetCharFont(int pos, LyXFont const & font);
209 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
212 /* Private structures and variables */
224 LyXCursor selection_start_cursor;
226 LyXCursor selection_end_cursor;
228 mutable LyXCursor cursor;
230 mutable LyXCursor old_cursor;
238 mutable bool init_inset;
240 UpdatableInset * the_locking_inset;
253 typedef std::vector<row_struct> RowList;
255 mutable RowList rows;
257 InsetText & operator = (InsetText const & it) {
259 buffer = it.buffer; // suspect
260 current_font = it.current_font;
261 real_current_font = it.real_current_font;
262 maxAscent = it.maxAscent;
263 maxDescent = it.maxDescent;
264 insetWidth = it.insetWidth;
265 inset_pos = it.inset_pos;
266 inset_x = it.inset_x;
267 inset_y = it.inset_y;
268 interline_space = it.interline_space;
269 selection_start_cursor = selection_end_cursor = cursor = it.cursor;
271 no_selection = it.no_selection;
272 the_locking_inset = it.the_locking_inset; // suspect