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"
34 * A text inset is like a TeX box to write full text
35 * (including styles and other insets) in a given space.
37 class InsetText : public UpdatableInset {
40 enum { TEXT_TO_INSET_OFFSET = 2 };
45 InsetText(InsetText const &);
49 Inset * Clone() const;
51 InsetText & operator= (InsetText const & it);
53 void clear() const { par->clearContents(); }
55 void Read(Buffer const *, LyXLex &);
57 void Write(Buffer const *, std::ostream &) const;
59 int ascent(Painter &, LyXFont const &) const;
61 int descent(Painter &, LyXFont const &) const;
63 int width(Painter &, LyXFont const & f) const;
65 void draw(Painter & pain, LyXFont const &, int , float &) const;
67 void update(BufferView *, LyXFont const &) const;
69 char const * EditMessage() const;
71 void Edit(BufferView *, int, int, unsigned int);
73 void InsetUnlock(BufferView *);
75 bool LockInsetInInset(BufferView *, UpdatableInset *);
77 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
79 bool UpdateInsetInInset(BufferView *, Inset *);
81 void InsetButtonRelease(BufferView *, int, int, int);
83 void InsetButtonPress(BufferView *, int, int, int);
85 void InsetMotionNotify(BufferView *, int, int, int);
87 void InsetKeyPress(XKeyEvent *);
89 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
91 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
93 int Ascii(Buffer const *, std::ostream &) const { return 0; }
95 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
97 int DocBook(Buffer const *, std::ostream &) const { return 0; }
99 void Validate(LaTeXFeatures & features) const;
101 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
103 void GetCursorPos(int & x, int & y) const;
107 void ToggleInsetCursor(BufferView *);
109 bool InsertInset(BufferView *, Inset *);
111 UpdatableInset * GetLockingInset();
113 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
115 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
117 void init(InsetText const * ins = 0);
119 void SetParagraphData(LyXParagraph *);
121 void SetAutoBreakRows(bool);
123 void SetDrawLockedFrame(bool);
125 void SetFrameColor(LColor::color);
127 void computeTextRows(Painter &) const;
134 void UpdateLocal(BufferView *, bool what, bool mark_dirty);
136 void WriteParagraphData(Buffer const *, std::ostream &) const;
138 void resetPos(Painter &) const;
140 void drawSelection(Painter &, int pos, int baseline, float x);
142 void SingleHeight(Painter &, LyXParagraph * par,int pos,
143 int & asc, int & desc) const;
145 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
147 LyXFont GetFont(Buffer const *, LyXParagraph * par, int pos) const;
149 virtual LyXFont GetDrawFont(Buffer const *, LyXParagraph * par, int pos) const;
151 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
155 LyXFont current_font;
157 LyXFont real_current_font;
159 mutable int maxAscent;
161 mutable int maxDescent;
163 mutable int insetWidth;
165 mutable int drawTextXOffset;
166 mutable int drawTextYOffset;
169 bool drawLockedFrame;
171 LColor::color frame_color;
175 void drawRowSelection(Painter &, int startpos, int endpos, int row,
176 int baseline, float x) const;
178 void drawRowText(Painter &, int startpos, int endpos, int baseline,
181 void computeBaselines(int) const;
183 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
185 void ShowInsetCursor(BufferView *);
187 void HideInsetCursor(BufferView *);
189 void setPos(Painter &, int x, int y) const;
191 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
193 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
195 UpdatableInset::RESULT moveUp(BufferView *);
197 UpdatableInset::RESULT moveDown(BufferView *);
201 bool cutSelection(Buffer const *);
203 bool copySelection(Buffer const *);
205 bool pasteSelection(Buffer const *);
207 bool hasSelection() const
208 { return (selection_start_cursor != selection_end_cursor); }
210 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
214 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
219 LyXParagraph * cpar() const;
222 /* Private structures and variables */
234 LyXCursor selection_start_cursor;
236 LyXCursor selection_end_cursor;
238 mutable LyXCursor cursor;
240 mutable LyXCursor old_cursor;
248 mutable bool init_inset;
250 UpdatableInset * the_locking_inset;
263 typedef std::vector<row_struct> RowList;
265 mutable RowList rows;
267 LyXParagraph * old_par;