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 {
41 enum { TEXT_TO_INSET_OFFSET = 2 };
55 InsetText(InsetText const &);
59 Inset * Clone() const;
61 InsetText & operator= (InsetText const & it);
63 void clear() const { par->clearContents(); }
65 void Read(Buffer const *, LyXLex &);
67 void Write(Buffer const *, std::ostream &) const;
69 int ascent(Painter &, LyXFont const &) const;
71 int descent(Painter &, LyXFont const &) const;
73 int width(Painter &, LyXFont const & f) const;
75 int textWidth(Painter &) const;
77 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
79 void update(BufferView *, LyXFont const &, bool =false);
81 char const * EditMessage() const;
83 void Edit(BufferView *, int, int, unsigned int);
85 bool IsTextInset() const { return true; }
87 bool doClearArea() const { return !locked; }
89 void InsetUnlock(BufferView *);
91 bool LockInsetInInset(BufferView *, UpdatableInset *);
93 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
95 bool UpdateInsetInInset(BufferView *, Inset *);
97 void InsetButtonRelease(BufferView *, int, int, int);
99 void InsetButtonPress(BufferView *, int, int, int);
101 void InsetMotionNotify(BufferView *, int, int, int);
103 void InsetKeyPress(XKeyEvent *);
105 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
107 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
109 int Ascii(Buffer const *, std::ostream &) const { return 0; }
111 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
113 int DocBook(Buffer const *, std::ostream &) const { return 0; }
115 void Validate(LaTeXFeatures & features) const;
117 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
119 void GetCursorPos(BufferView *, int & x, int & y) const;
123 void ToggleInsetCursor(BufferView *);
125 bool InsertInset(BufferView *, Inset *);
127 UpdatableInset * GetLockingInset();
129 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
131 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
133 void init(InsetText const * ins = 0);
135 void SetParagraphData(LyXParagraph *);
137 void SetAutoBreakRows(bool);
139 void SetDrawLockedFrame(bool);
141 void SetFrameColor(LColor::color);
143 LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
145 LyXText * getLyXText(BufferView *) const;
146 void deleteLyXText(BufferView *);
152 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
154 void WriteParagraphData(Buffer const *, std::ostream &) const;
156 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
158 mutable int drawTextXOffset;
159 mutable int drawTextYOffset;
162 bool drawLockedFrame;
164 LColor::color frame_color;
168 typedef std::map<BufferView *, LyXText *> Cache;
170 typedef Cache::value_type value_type;
172 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
174 void ShowInsetCursor(BufferView *);
176 void HideInsetCursor(BufferView *);
178 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
180 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
182 UpdatableInset::RESULT moveUp(BufferView *);
184 UpdatableInset::RESULT moveDown(BufferView *);
186 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
190 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
193 int cx(BufferView *) const;
194 int cy(BufferView *) const;
195 int cpos(BufferView *) const;
196 LyXParagraph * cpar(BufferView *) const;
197 Row * crow(BufferView *) const;
199 /* Private structures and variables */
206 mutable int last_width;
207 mutable int last_height;
222 mutable UpdateCodes need_update;
224 UpdatableInset * the_locking_inset;
226 LyXParagraph * old_par;