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 char const * EditMessage() const;
69 void Edit(BufferView *, int, int, unsigned int);
71 void InsetUnlock(BufferView *);
73 bool LockInsetInInset(BufferView *, UpdatableInset *);
75 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
77 bool UpdateInsetInInset(BufferView *, Inset *);
79 void InsetButtonRelease(BufferView *, int, int, int);
81 void InsetButtonPress(BufferView *, int, int, int);
83 void InsetMotionNotify(BufferView *, int, int, int);
85 void InsetKeyPress(XKeyEvent *);
87 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
89 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
91 int Ascii(Buffer const *, std::ostream &) const { return 0; }
93 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
95 int DocBook(Buffer const *, std::ostream &) const { return 0; }
97 void Validate(LaTeXFeatures & features) const;
99 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
101 void GetCursorPos(int & x, int & y) const;
105 void ToggleInsetCursor(BufferView *);
107 bool InsertInset(BufferView *, Inset *);
109 UpdatableInset * GetLockingInset();
111 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
113 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
115 void init(InsetText const * ins = 0);
117 void SetParagraphData(LyXParagraph *);
119 void SetAutoBreakRows(bool);
121 void SetDrawLockedFrame(bool);
123 void SetFrameColor(LColor::color);
125 void computeTextRows(Painter &) const;
132 void UpdateLocal(BufferView *, bool);
134 void WriteParagraphData(Buffer const *, std::ostream &) const;
136 void resetPos(Painter &) const;
138 void drawSelection(Painter &, int pos, int baseline, float x);
140 void SingleHeight(Painter &, LyXParagraph * par,int pos,
141 int & asc, int & desc) const;
143 int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
145 LyXFont GetFont(Buffer const *, LyXParagraph * par, int pos) const;
147 virtual LyXFont GetDrawFont(Buffer const *, LyXParagraph * par, int pos) const;
149 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
153 LyXFont current_font;
155 LyXFont real_current_font;
157 mutable int maxAscent;
159 mutable int maxDescent;
161 mutable int insetWidth;
163 mutable int drawTextXOffset;
164 mutable int drawTextYOffset;
167 bool drawLockedFrame;
169 LColor::color frame_color;
173 void drawRowSelection(Painter &, int startpos, int endpos, int row,
174 int baseline, float x) const;
176 void drawRowText(Painter &, int startpos, int endpos, int baseline,
179 void computeBaselines(int) const;
181 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
183 void ShowInsetCursor(BufferView *);
185 void HideInsetCursor(BufferView *);
187 void setPos(Painter &, int x, int y) const;
189 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
191 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
193 UpdatableInset::RESULT moveUp(BufferView *);
195 UpdatableInset::RESULT moveDown(BufferView *);
199 bool cutSelection(Buffer const *);
201 bool copySelection(Buffer const *);
203 bool pasteSelection(Buffer const *);
205 bool hasSelection() const
206 { return (selection_start_cursor != selection_end_cursor); }
208 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
212 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
215 /* Private structures and variables */
227 LyXCursor selection_start_cursor;
229 LyXCursor selection_end_cursor;
231 mutable LyXCursor cursor;
233 mutable LyXCursor old_cursor;
241 mutable bool init_inset;
243 UpdatableInset * the_locking_inset;
256 typedef std::vector<row_struct> RowList;
258 mutable RowList rows;