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"
35 * A text inset is like a TeX box to write full text
36 * (including styles and other insets) in a given space.
38 class InsetText : public UpdatableInset {
61 InsetText(InsetText const &);
65 Inset * Clone() const;
67 InsetText & operator= (InsetText const & it);
71 void Read(Buffer const *, LyXLex &);
73 void Write(Buffer const *, std::ostream &) const;
75 int ascent(BufferView *, LyXFont const &) const;
77 int descent(BufferView *, LyXFont const &) const;
79 int width(BufferView *, LyXFont const & f) const;
81 int textWidth(Painter &) const;
83 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
85 void update(BufferView *, LyXFont const &, bool =false);
87 char const * EditMessage() const;
89 void Edit(BufferView *, int, int, unsigned int);
91 bool IsTextInset() const { return true; }
93 bool doClearArea() const { return !locked; }
95 void InsetUnlock(BufferView *);
97 bool LockInsetInInset(BufferView *, UpdatableInset *);
99 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
101 bool UpdateInsetInInset(BufferView *, Inset *);
103 void InsetButtonRelease(BufferView *, int, int, int);
105 void InsetButtonPress(BufferView *, int, int, int);
107 void InsetMotionNotify(BufferView *, int, int, int);
109 void InsetKeyPress(XKeyEvent *);
111 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
113 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
115 int Ascii(Buffer const *, std::ostream &) const { return 0; }
117 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
119 int DocBook(Buffer const *, std::ostream &) const { return 0; }
121 void Validate(LaTeXFeatures & features) const;
123 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
125 void GetCursorPos(BufferView *, int & x, int & y) const;
129 void ToggleInsetCursor(BufferView *);
131 bool InsertInset(BufferView *, Inset *);
133 UpdatableInset * GetLockingInset();
135 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
137 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
139 int getMaxWidth(Painter &, UpdatableInset const *) const;
141 void init(InsetText const * ins = 0);
143 void WriteParagraphData(Buffer const *, std::ostream &) const;
145 void SetParagraphData(LyXParagraph *);
147 void SetAutoBreakRows(bool);
149 void SetDrawFrame(BufferView *, DrawFrame);
151 void SetFrameColor(BufferView *, LColor::color);
153 // LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
155 LyXText * getLyXText(BufferView *) const;
156 void deleteLyXText(BufferView *, bool recursive=true) const;
157 void resizeLyXText(BufferView *) const;
161 mutable UpdateCodes need_update;
165 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
167 mutable int drawTextXOffset;
168 mutable int drawTextYOffset;
173 LColor::color frame_color;
177 typedef std::map<BufferView *, LyXText *> Cache;
179 typedef Cache::value_type value_type;
181 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
183 void ShowInsetCursor(BufferView *);
185 void HideInsetCursor(BufferView *);
187 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
189 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
191 UpdatableInset::RESULT moveUp(BufferView *);
193 UpdatableInset::RESULT moveDown(BufferView *);
195 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
199 bool checkAndActivateInset(BufferView * bv, bool behind);
200 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
203 int cx(BufferView *) const;
204 int cy(BufferView *) const;
205 int cpos(BufferView *) const;
206 LyXParagraph * cpar(BufferView *) const;
207 Row * crow(BufferView *) const;
209 /// This instead of a macro
210 LyXText * TEXT(BufferView * bv) const {
211 return getLyXText(bv);
214 /* Private structures and variables */
218 mutable int insetAscent;
219 mutable int insetDescent;
220 mutable int insetWidth;
221 mutable int last_width;
222 mutable int last_height;
225 LyXParagraph * inset_par;
239 UpdatableInset * the_locking_inset;
241 LyXParagraph * old_par;