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 &,
114 bool fragile, bool free_spc) const;
116 int Ascii(Buffer const *, std::ostream &) const { return 0; }
118 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
120 int DocBook(Buffer const *, std::ostream &) const { return 0; }
122 void Validate(LaTeXFeatures & features) const;
124 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
126 void GetCursorPos(BufferView *, int & x, int & y) const;
130 void ToggleInsetCursor(BufferView *);
132 bool InsertInset(BufferView *, Inset *);
134 UpdatableInset * GetLockingInset();
136 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
138 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
140 int getMaxWidth(Painter &, UpdatableInset const *) const;
142 void init(InsetText const * ins = 0);
144 void WriteParagraphData(Buffer const *, std::ostream &) const;
146 void SetParagraphData(LyXParagraph *);
148 void SetAutoBreakRows(bool);
150 void SetDrawFrame(BufferView *, DrawFrame);
152 void SetFrameColor(BufferView *, LColor::color);
154 // LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
156 LyXText * getLyXText(BufferView *) const;
158 void deleteLyXText(BufferView *, bool recursive=true) const;
160 void resizeLyXText(BufferView *) const;
164 mutable UpdateCodes need_update;
168 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
170 mutable int drawTextXOffset;
172 mutable int drawTextYOffset;
178 LColor::color frame_color;
182 typedef std::map<BufferView *, LyXText *> Cache;
184 typedef Cache::value_type value_type;
186 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
188 void ShowInsetCursor(BufferView *);
190 void HideInsetCursor(BufferView *);
192 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
194 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
196 UpdatableInset::RESULT moveUp(BufferView *);
198 UpdatableInset::RESULT moveDown(BufferView *);
200 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
204 bool checkAndActivateInset(BufferView * bv, bool behind);
206 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
209 int cx(BufferView *) const;
211 int cy(BufferView *) const;
213 int cpos(BufferView *) const;
215 LyXParagraph * cpar(BufferView *) const;
217 Row * crow(BufferView *) const;
219 /// This instead of a macro
220 LyXText * TEXT(BufferView * bv) const {
221 return getLyXText(bv);
224 /* Private structures and variables */
228 mutable int insetAscent;
230 mutable int insetDescent;
232 mutable int insetWidth;
234 mutable int last_width;
236 mutable int last_height;
240 LyXParagraph * inset_par;
254 UpdatableInset * the_locking_inset;
256 LyXParagraph * old_par;