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;
125 Buffer * BufferOwner() const { return buffer; }
131 void UpdateLocal(BufferView *, bool);
133 void WriteParagraphData(std::ostream &) const;
135 void resetPos(Painter &) const;
137 void drawSelection(Painter &, int pos, int baseline, float x);
139 void SingleHeight(Painter &, LyXParagraph * par,int pos,
140 int & asc, int & desc) const;
142 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
144 LyXFont GetFont(LyXParagraph * par, int pos) const;
146 virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
148 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
152 LyXFont current_font;
154 LyXFont real_current_font;
156 mutable int maxAscent;
158 mutable int maxDescent;
160 mutable int insetWidth;
162 mutable int drawTextXOffset;
163 mutable int drawTextYOffset;
166 bool drawLockedFrame;
168 LColor::color frame_color;
172 void drawRowSelection(Painter &, int startpos, int endpos, int row,
173 int baseline, float x) const;
175 void drawRowText(Painter &, int startpos, int endpos, int baseline,
178 void computeBaselines(int) const;
180 int BeginningOfMainBody(LyXParagraph * par) const;
182 void ShowInsetCursor(BufferView *);
184 void HideInsetCursor(BufferView *);
186 void setPos(Painter &, int x, int y) const;
188 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
190 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
192 UpdatableInset::RESULT moveUp(BufferView *);
194 UpdatableInset::RESULT moveDown(BufferView *);
200 bool copySelection();
202 bool pasteSelection();
204 bool hasSelection() const
205 { return (selection_start_cursor != selection_end_cursor); }
207 void SetCharFont(int pos, LyXFont const & font);
211 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
214 /* Private structures and variables */
226 LyXCursor selection_start_cursor;
228 LyXCursor selection_end_cursor;
230 mutable LyXCursor cursor;
232 mutable LyXCursor old_cursor;
240 mutable bool init_inset;
242 UpdatableInset * the_locking_inset;
255 typedef std::vector<row_struct> RowList;
257 mutable RowList rows;
259 InsetText & operator = (InsetText const & it) {
261 buffer = it.buffer; // suspect
262 current_font = it.current_font;
263 real_current_font = it.real_current_font;
264 maxAscent = it.maxAscent;
265 maxDescent = it.maxDescent;
266 insetWidth = it.insetWidth;
267 inset_pos = it.inset_pos;
268 inset_x = it.inset_x;
269 inset_y = it.inset_y;
270 interline_space = it.interline_space;
271 selection_start_cursor = selection_end_cursor = cursor = it.cursor;
273 no_selection = it.no_selection;
274 the_locking_inset = it.the_locking_inset; // suspect