2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
10 *======================================================
12 // The pristine updatable inset: Text
24 #include "lyxcursor.h"
25 #include <boost/smart_ptr.hpp>
37 A text inset is like a TeX box to write full text
38 (including styles and other insets) in a given space.
41 class InsetText : public UpdatableInset {
44 /// numbers need because of test if codeA < codeB
77 InsetText(InsetText const &);
81 Inset * clone(Buffer const &) const;
83 InsetText & operator=(InsetText const & it);
87 void read(Buffer const *, LyXLex &);
89 void write(Buffer const *, std::ostream &) const;
91 int ascent(BufferView *, LyXFont const &) const;
93 int descent(BufferView *, LyXFont const &) const;
95 int width(BufferView *, LyXFont const & f) const;
97 int textWidth(BufferView *) const;
99 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
101 void update(BufferView *, LyXFont const &, bool =false);
103 void setUpdateStatus(BufferView *, int what) const;
105 string const editMessage() const;
107 void edit(BufferView *, int, int, unsigned int);
109 bool isTextInset() const { return true; }
111 bool doClearArea() const;
113 void insetUnlock(BufferView *);
115 bool lockInsetInInset(BufferView *, UpdatableInset *);
117 bool unlockInsetInInset(BufferView *,
118 UpdatableInset *, bool lr = false);
120 bool updateInsetInInset(BufferView *, Inset *);
122 void insetButtonRelease(BufferView *, int, int, int);
124 void insetButtonPress(BufferView *, int, int, int);
126 void insetMotionNotify(BufferView *, int, int, int);
128 void insetKeyPress(XKeyEvent *);
130 UpdatableInset::RESULT localDispatch(BufferView *,
131 kb_action, string const &);
133 int latex(Buffer const *, std::ostream &,
134 bool fragile, bool free_spc) const;
136 int ascii(Buffer const *, std::ostream &, int linelen) const;
138 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
140 int docBook(Buffer const *, std::ostream &) const ;
142 void validate(LaTeXFeatures & features) const;
144 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
146 void getCursorPos(BufferView *, int & x, int & y) const;
148 unsigned int insetInInsetY();
150 void toggleInsetCursor(BufferView *);
152 bool insertInset(BufferView *, Inset *);
154 UpdatableInset * getLockingInset();
156 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
158 void setFont(BufferView *, LyXFont const &,
159 bool toggleall = false,
160 bool selectall = false);
162 int getMaxWidth(BufferView *, UpdatableInset const *) const;
164 void init(InsetText const * ins = 0);
166 void writeParagraphData(Buffer const *, std::ostream &) const;
168 void setParagraphData(Paragraph *);
170 void setText(string const &);
172 void setAutoBreakRows(bool);
174 void setDrawFrame(BufferView *, DrawFrame);
176 void setFrameColor(BufferView *, LColor::color);
178 LyXText * getLyXText(BufferView const *,
179 bool const recursive = false) const;
181 void deleteLyXText(BufferView *, bool recursive = true) const;
183 void resizeLyXText(BufferView *, bool force = false) const;
185 bool showInsetDialog(BufferView *) const;
187 std::vector<string> const getLabelList() const;
191 int scroll(bool recursive=true) const;
193 void scroll(BufferView *bv, float sx) const {
194 UpdatableInset::scroll(bv, sx);
197 void scroll(BufferView *bv, int offset) const {
198 UpdatableInset::scroll(bv, offset);
201 void selectAll(BufferView *bv);
203 void clearSelection(BufferView *bv);
207 mutable int need_update;
211 void updateLocal(BufferView *, int what, bool mark_dirty);
213 mutable int drawTextXOffset;
215 mutable int drawTextYOffset;
219 DrawFrame drawFrame_;
221 LColor::color frame_color;
225 typedef std::map<BufferView *, boost::shared_ptr<LyXText> > Cache;
227 typedef Cache::value_type value_type;
229 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
231 void showInsetCursor(BufferView *, bool show=true);
233 void hideInsetCursor(BufferView *);
235 UpdatableInset::RESULT moveRight(BufferView *,
236 bool activate_inset = true,
237 bool selecting = false);
239 UpdatableInset::RESULT moveLeft(BufferView *,
240 bool activate_inset = true,
241 bool selecting = false);
243 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
244 bool activate_inset = true,
245 bool selecting = false);
247 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
248 bool activate_inset = true,
249 bool selecting = false);
252 UpdatableInset::RESULT moveUp(BufferView *);
254 UpdatableInset::RESULT moveDown(BufferView *);
256 void setCharFont(Buffer const *, int pos, LyXFont const & font);
258 string const getText(int);
260 bool checkAndActivateInset(BufferView * bv, bool behind);
262 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
265 void removeNewlines();
267 int cx(BufferView *) const;
269 int cy(BufferView *) const;
271 Paragraph::size_type cpos(BufferView *) const;
273 Paragraph * cpar(BufferView *) const;
275 bool cboundary(BufferView *) const;
277 Row * crow(BufferView *) const;
279 void drawFrame(Painter &, bool cleared) const;
281 void clearFrame(Painter &, bool cleared) const;
283 void clearInset(Painter &, int baseline, bool & cleared) const;
285 /* Private structures and variables */
289 mutable int insetAscent;
291 mutable int insetDescent;
293 mutable int insetWidth;
295 mutable int last_width;
297 mutable int last_height;
301 Paragraph * inset_par;
303 Paragraph::size_type inset_pos;
311 mutable unsigned int old_max_width;
317 UpdatableInset * the_locking_inset;
323 mutable int last_drawn_width;
325 mutable bool frame_is_visible;
327 mutable BufferView * cached_bview;
329 mutable boost::shared_ptr<LyXText> cached_text;