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