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
25 #include "paragraph.h"
26 #include "lyxcursor.h"
27 #include <boost/smart_ptr.hpp>
38 A text inset is like a TeX box to write full text
39 (including styles and other insets) in a given space.
42 class InsetText : public UpdatableInset {
45 /// numbers need because of test if codeA < codeB
78 InsetText(InsetText const &, bool same_id = false);
82 Inset * clone(Buffer const &, bool same_id = false) const;
84 InsetText & operator=(InsetText const & it);
88 void read(Buffer const *, LyXLex &);
90 void write(Buffer const *, std::ostream &) const;
92 int ascent(BufferView *, LyXFont const &) const;
94 int descent(BufferView *, LyXFont const &) const;
96 int width(BufferView *, LyXFont const & f) const;
98 int textWidth(BufferView *) const;
100 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
102 void update(BufferView *, LyXFont const &, bool =false);
104 void setUpdateStatus(BufferView *, int what) const;
106 string const editMessage() const;
108 void edit(BufferView *, int, int, unsigned int);
110 bool isTextInset() const { return true; }
112 bool doClearArea() const;
114 void insetUnlock(BufferView *);
116 bool lockInsetInInset(BufferView *, UpdatableInset *);
118 bool unlockInsetInInset(BufferView *,
119 UpdatableInset *, bool lr = false);
121 bool updateInsetInInset(BufferView *, Inset *);
123 void insetButtonRelease(BufferView *, int, int, int);
125 void insetButtonPress(BufferView *, int, int, int);
127 void insetMotionNotify(BufferView *, int, int, int);
129 void insetKeyPress(XKeyEvent *);
131 UpdatableInset::RESULT localDispatch(BufferView *,
132 kb_action, string const &);
134 int latex(Buffer const *, std::ostream &,
135 bool fragile, bool free_spc) const;
137 int ascii(Buffer const *, std::ostream &, int linelen) const;
139 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
141 int docBook(Buffer const *, std::ostream &) const ;
143 void validate(LaTeXFeatures & features) const;
145 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
147 void getCursorPos(BufferView *, int & x, int & y) const;
149 unsigned int insetInInsetY();
151 void toggleInsetCursor(BufferView *);
153 bool insertInset(BufferView *, Inset *);
155 bool insertInsetAllowed(Inset *) const;
156 bool insertInsetAllowed(Inset::Code) const;
158 UpdatableInset * getLockingInset() const;
160 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
162 void setFont(BufferView *, LyXFont const &,
163 bool toggleall = false,
164 bool selectall = false);
166 int getMaxWidth(BufferView *, UpdatableInset const *) const;
168 void init(InsetText const * ins = 0, bool same_id = false);
170 void writeParagraphData(Buffer const *, std::ostream &) const;
172 void setParagraphData(Paragraph *);
174 void setText(string const &);
176 void setAutoBreakRows(bool);
178 void setDrawFrame(BufferView *, DrawFrame);
180 void setFrameColor(BufferView *, LColor::color);
182 LyXText * getLyXText(BufferView const *,
183 bool const recursive = false) const;
185 void deleteLyXText(BufferView *, bool recursive = true) const;
187 void resizeLyXText(BufferView *, bool force = false) const;
189 bool showInsetDialog(BufferView *) const;
191 std::vector<string> const getLabelList() const;
195 int scroll(bool recursive=true) const;
197 void scroll(BufferView *bv, float sx) const {
198 UpdatableInset::scroll(bv, sx);
201 void scroll(BufferView *bv, int offset) const {
202 UpdatableInset::scroll(bv, offset);
205 void selectAll(BufferView *bv);
207 void clearSelection(BufferView *bv);
209 Paragraph * getParFromID(int id) const;
211 Inset * getInsetFromID(int id) const;
213 Paragraph * firstParagraph() const;
215 LyXCursor const & cursor(BufferView *) const;
217 Paragraph * paragraph() const;
219 void paragraph(Paragraph *);
221 string selectNextWord(BufferView *, float & value) const;
222 void selectSelectedWord(BufferView *);
223 void toggleSelection(BufferView *, bool kill_selection);
225 mutable int need_update;
229 void updateLocal(BufferView *, int what, bool mark_dirty);
231 mutable int drawTextXOffset;
233 mutable int drawTextYOffset;
237 DrawFrame drawFrame_;
239 LColor::color frame_color;
243 InnerCache(boost::shared_ptr<LyXText>);
245 boost::shared_ptr<LyXText> text;
249 typedef std::map<BufferView *, struct InnerCache > Cache;
251 typedef Cache::value_type value_type;
253 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
255 void showInsetCursor(BufferView *, bool show=true);
257 void hideInsetCursor(BufferView *);
259 UpdatableInset::RESULT moveRight(BufferView *,
260 bool activate_inset = true,
261 bool selecting = false);
263 UpdatableInset::RESULT moveLeft(BufferView *,
264 bool activate_inset = true,
265 bool selecting = false);
267 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
268 bool activate_inset = true,
269 bool selecting = false);
271 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
272 bool activate_inset = true,
273 bool selecting = false);
276 UpdatableInset::RESULT moveUp(BufferView *);
278 UpdatableInset::RESULT moveDown(BufferView *);
280 void setCharFont(Buffer const *, int pos, LyXFont const & font);
282 string const getText(int);
284 bool checkAndActivateInset(BufferView * bv, bool behind);
286 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
289 void removeNewlines();
291 int cx(BufferView *) const;
293 int cy(BufferView *) const;
295 Paragraph::size_type cpos(BufferView *) const;
297 Paragraph * cpar(BufferView *) const;
299 bool cboundary(BufferView *) const;
301 Row * crow(BufferView *) const;
303 void drawFrame(Painter &, bool cleared) const;
305 void clearFrame(Painter &, bool cleared) const;
307 void clearInset(Painter &, int baseline, bool & cleared) const;
309 void saveLyXTextState(LyXText *) const;
310 void restoreLyXTextState(BufferView *, LyXText *) const;
312 /* Private structures and variables */
318 mutable int insetAscent;
320 mutable int insetDescent;
322 mutable int insetWidth;
324 mutable int last_width;
326 mutable int last_height;
330 Paragraph * inset_par;
332 Paragraph::size_type inset_pos;
340 mutable unsigned int old_max_width;
346 UpdatableInset * the_locking_inset;
352 mutable int last_drawn_width;
354 mutable bool frame_is_visible;
356 mutable BufferView * cached_bview;
358 mutable boost::shared_ptr<LyXText> cached_text;
360 mutable struct save_state {
362 Paragraph * selstartpar;
363 Paragraph * selendpar;
364 Paragraph::size_type pos;
365 Paragraph::size_type selstartpos;
366 Paragraph::size_type selendpos;
368 bool selstartboundary;
374 // this is needed globally so we know that we're using it actually and
375 // so the LyXText-Cache is not erased until used!
376 mutable LyXText * lt;