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 };
54 InsetText(InsetText const &);
58 Inset * Clone() const;
60 InsetText & operator= (InsetText const & it);
62 void clear() const { par->clearContents(); }
64 void Read(Buffer const *, LyXLex &);
66 void Write(Buffer const *, std::ostream &) const;
68 int ascent(Painter &, LyXFont const &) const;
70 int descent(Painter &, LyXFont const &) const;
72 int width(Painter &, LyXFont const & f) const;
74 void draw(BufferView *, LyXFont const &, int , float &) const;
76 void update(BufferView *, LyXFont const &, bool =false);
78 char const * EditMessage() const;
80 void Edit(BufferView *, int, int, unsigned int);
82 bool IsTextInset() const { return true; }
84 bool doClearArea() const { return !locked; }
86 void InsetUnlock(BufferView *);
88 bool LockInsetInInset(BufferView *, UpdatableInset *);
90 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
92 bool UpdateInsetInInset(BufferView *, Inset *);
94 void InsetButtonRelease(BufferView *, int, int, int);
96 void InsetButtonPress(BufferView *, int, int, int);
98 void InsetMotionNotify(BufferView *, int, int, int);
100 void InsetKeyPress(XKeyEvent *);
102 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
104 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
106 int Ascii(Buffer const *, std::ostream &) const { return 0; }
108 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
110 int DocBook(Buffer const *, std::ostream &) const { return 0; }
112 void Validate(LaTeXFeatures & features) const;
114 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
116 void GetCursorPos(BufferView *, int & x, int & y) const;
120 void ToggleInsetCursor(BufferView *);
122 bool InsertInset(BufferView *, Inset *);
124 UpdatableInset * GetLockingInset();
126 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
128 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
130 void init(InsetText const * ins = 0);
132 void SetParagraphData(LyXParagraph *);
134 void SetAutoBreakRows(bool);
136 void SetDrawLockedFrame(bool);
138 void SetFrameColor(LColor::color);
140 LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
142 LyXText * getLyXText(BufferView *) const;
143 void deleteLyXText(BufferView *);
149 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
151 void WriteParagraphData(Buffer const *, std::ostream &) const;
153 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
155 mutable int drawTextXOffset;
156 mutable int drawTextYOffset;
159 bool drawLockedFrame;
161 LColor::color frame_color;
165 typedef std::map<BufferView *, LyXText *> Cache;
167 typedef Cache::value_type value_type;
169 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
171 void ShowInsetCursor(BufferView *);
173 void HideInsetCursor(BufferView *);
175 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
177 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
179 UpdatableInset::RESULT moveUp(BufferView *);
181 UpdatableInset::RESULT moveDown(BufferView *);
183 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
187 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
190 int cx(BufferView *) const;
191 int cy(BufferView *) const;
192 int cpos(BufferView *) const;
193 LyXParagraph * cpar(BufferView *) const;
194 Row * crow(BufferView *) const;
196 /* Private structures and variables */
216 mutable UpdateCodes need_update;
218 UpdatableInset * the_locking_inset;
220 LyXParagraph * old_par;