4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
22 #include "ParagraphList.h"
24 #include "support/types.h"
26 #include <boost/shared_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
75 InsetText(BufferParams const &);
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 *, bool fordraw = false) 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, mouse_button::state);
110 void edit(BufferView *, bool front = true);
112 bool isTextInset() const { return true; }
114 bool doClearArea() const;
116 void insetUnlock(BufferView *);
118 bool lockInsetInInset(BufferView *, UpdatableInset *);
120 bool unlockInsetInInset(BufferView *,
121 UpdatableInset *, bool lr = false);
123 bool updateInsetInInset(BufferView *, Inset *);
125 RESULT localDispatch(FuncRequest const &);
127 int latex(Buffer const *, std::ostream &,
128 bool fragile, bool free_spc) const;
130 int ascii(Buffer const *, std::ostream &, int linelen) const;
132 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
134 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
136 void validate(LaTeXFeatures & features) const;
138 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
140 void getCursorPos(BufferView *, int & x, int & y) const;
142 int insetInInsetY() const;
144 void toggleInsetCursor(BufferView *);
146 void showInsetCursor(BufferView *, bool show = true);
148 void hideInsetCursor(BufferView *);
150 void fitInsetCursor(BufferView *) const;
152 bool insertInset(BufferView *, Inset *);
154 bool insetAllowed(Inset::Code) const;
156 UpdatableInset * getLockingInset() const;
158 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
160 void setFont(BufferView *, LyXFont const &,
161 bool toggleall = false,
162 bool selectall = false);
164 int getMaxWidth(BufferView *, UpdatableInset const *) const;
166 void init(InsetText const * ins = 0, bool same_id = false);
168 void writeParagraphData(Buffer const *, std::ostream &) const;
170 void setParagraphData(Paragraph *, bool same_id = false);
172 void setText(string const &, LyXFont const &);
174 void setAutoBreakRows(bool);
176 bool getAutoBreakRows() const { return autoBreakRows; }
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 Paragraph * getFirstParagraph(int) const;
217 LyXCursor const & cursor(BufferView *) const;
219 Paragraph * paragraph() const;
221 void paragraph(Paragraph *);
223 bool allowSpellcheck() { return true; }
226 selectNextWordToSpellcheck(BufferView *, float & value) const;
228 void selectSelectedWord(BufferView *);
230 void toggleSelection(BufferView *, bool kill_selection);
232 bool searchForward(BufferView *, string const &,
233 bool = true, bool = false);
235 bool searchBackward(BufferView *, string const &,
236 bool = true, bool = false);
238 bool checkInsertChar(LyXFont &);
240 void getDrawFont(LyXFont &) const;
242 void appendParagraphs(BufferParams const & bparams, Paragraph *);
244 void addPreview(grfx::PreviewLoader &) const;
247 // Public structures and variables
249 mutable int need_update;
253 void updateLocal(BufferView *, int what, bool mark_dirty) const;
254 /// set parameters for an initial lock of this inset
255 void lockInset(BufferView *);
256 /// lock an inset inside this one
257 void lockInset(BufferView *, UpdatableInset *);
259 mutable int drawTextXOffset;
261 mutable int drawTextYOffset;
265 DrawFrame drawFrame_;
267 LColor::color frame_color;
271 void lfunMousePress(FuncRequest const &);
273 bool lfunMouseRelease(FuncRequest const &);
275 void lfunMouseMotion(FuncRequest const &);
280 InnerCache(boost::shared_ptr<LyXText>);
282 boost::shared_ptr<LyXText> text;
287 typedef std::map<BufferView *, InnerCache> Cache;
289 typedef Cache::value_type value_type;
291 int beginningOfMainBody(Paragraph * par) const;
293 RESULT moveRight(BufferView *,
294 bool activate_inset = true,
295 bool selecting = false);
297 RESULT moveLeft(BufferView *,
298 bool activate_inset = true,
299 bool selecting = false);
301 RESULT moveRightIntern(BufferView *, bool front,
302 bool activate_inset = true,
303 bool selecting = false);
305 RESULT moveLeftIntern(BufferView *, bool front,
306 bool activate_inset = true,
307 bool selecting = false);
310 RESULT moveUp(BufferView *);
312 RESULT moveDown(BufferView *);
314 void setCharFont(Buffer const *, int pos, LyXFont const & font);
316 bool checkAndActivateInset(BufferView * bv, bool front);
318 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
319 mouse_button::state button = mouse_button::none);
321 void removeNewlines();
323 int cx(BufferView *) const;
325 int cix(BufferView *) const;
327 int cy(BufferView *) const;
329 int ciy(BufferView *) const;
331 lyx::pos_type cpos(BufferView *) const;
333 Paragraph * cpar(BufferView *) const;
335 bool cboundary(BufferView *) const;
337 Row * crow(BufferView *) const;
339 void drawFrame(Painter &, bool cleared) const;
341 void clearFrame(Painter &, bool cleared) const;
343 void clearInset(BufferView *, int baseline, bool & cleared) const;
345 void saveLyXTextState(LyXText *) const;
347 void restoreLyXTextState(BufferView *, LyXText *) const;
349 void reinitLyXText() const;
351 void collapseParagraphs(BufferView *) const;
353 /* Private structures and variables */
355 ParagraphList paragraphs;
359 mutable int insetAscent;
361 mutable int insetDescent;
363 mutable int insetWidth;
367 Paragraph * inset_par;
369 lyx::pos_type inset_pos;
377 mutable int old_max_width;
381 UpdatableInset * the_locking_inset;
383 mutable Paragraph * old_par;
387 mutable int last_drawn_width;
389 mutable bool frame_is_visible;
391 mutable BufferView * cached_bview;
393 mutable boost::shared_ptr<LyXText> cached_text;
397 Paragraph * selstartpar;
398 Paragraph * selendpar;
400 lyx::pos_type selstartpos;
401 lyx::pos_type selendpos;
403 bool selstartboundary;
410 mutable save_state sstate;
413 // this is needed globally so we know that we're using it actually and
414 // so the LyXText-Cache is not erased until used!
415 mutable LyXText * lt;
417 // to remember old painted frame dimensions to clear it on the right spot!
424 bool in_update; /* as update is not reentrant! */
425 mutable BufferView * do_resize;
426 mutable bool do_reinit;
427 mutable bool in_insetAllowed;
429 // these are used to check for mouse movement in Motion selection code