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"
28 #include <boost/shared_ptr.hpp>
40 A text inset is like a TeX box to write full text
41 (including styles and other insets) in a given space.
44 class InsetText : public UpdatableInset {
47 /// numbers need because of test if codeA < codeB
77 InsetText(BufferParams const &);
80 InsetText(InsetText const &, bool same_id = false);
84 Inset * clone(Buffer const &, bool same_id = false) const;
86 InsetText & operator=(InsetText const & it);
90 void read(Buffer const *, LyXLex &);
92 void write(Buffer const *, std::ostream &) const;
94 int ascent(BufferView *, LyXFont const &) const;
96 int descent(BufferView *, LyXFont const &) const;
98 int width(BufferView *, LyXFont const & f) const;
100 int textWidth(BufferView *, bool fordraw = false) const;
102 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
104 void update(BufferView *, LyXFont const &, bool = false);
106 void setUpdateStatus(BufferView *, int what) const;
108 string const editMessage() const;
110 void edit(BufferView *, int, int, unsigned int);
112 void edit(BufferView *, bool front = true);
114 bool isTextInset() const { return true; }
116 bool doClearArea() const;
118 void insetUnlock(BufferView *);
120 bool lockInsetInInset(BufferView *, UpdatableInset *);
122 bool unlockInsetInInset(BufferView *,
123 UpdatableInset *, bool lr = false);
125 bool updateInsetInInset(BufferView *, Inset *);
127 bool insetButtonRelease(BufferView *, int, int, int);
129 void insetButtonPress(BufferView *, int, int, int);
131 void insetMotionNotify(BufferView *, int, int, int);
133 void insetKeyPress(XKeyEvent *);
135 UpdatableInset::RESULT localDispatch(BufferView *,
136 kb_action, string const &);
138 int latex(Buffer const *, std::ostream &,
139 bool fragile, bool free_spc) const;
141 int ascii(Buffer const *, std::ostream &, int linelen) const;
143 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
145 int docbook(Buffer const *, std::ostream &) const ;
147 void validate(LaTeXFeatures & features) const;
149 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
151 void getCursorPos(BufferView *, int & x, int & y) const;
153 int insetInInsetY() const;
155 void toggleInsetCursor(BufferView *);
157 void showInsetCursor(BufferView *, bool show = true);
159 void hideInsetCursor(BufferView *);
161 void fitInsetCursor(BufferView *) const;
163 bool insertInset(BufferView *, Inset *);
165 bool insetAllowed(Inset::Code) const;
167 UpdatableInset * getLockingInset() const;
169 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
171 void setFont(BufferView *, LyXFont const &,
172 bool toggleall = false,
173 bool selectall = false);
175 int getMaxWidth(BufferView *, UpdatableInset const *) const;
177 void init(InsetText const * ins = 0, bool same_id = false);
179 void writeParagraphData(Buffer const *, std::ostream &) const;
181 void setParagraphData(Paragraph *, bool same_id = false);
183 void setText(string const &, LyXFont const &);
185 void setAutoBreakRows(bool);
187 bool getAutoBreakRows() const { return autoBreakRows; }
189 void setDrawFrame(BufferView *, DrawFrame);
191 void setFrameColor(BufferView *, LColor::color);
193 LyXText * getLyXText(BufferView const *,
194 bool const recursive = false) const;
196 void deleteLyXText(BufferView *, bool recursive = true) const;
198 void resizeLyXText(BufferView *, bool force = false) const;
200 bool showInsetDialog(BufferView *) const;
202 std::vector<string> const getLabelList() const;
206 int scroll(bool recursive = true) const;
208 void scroll(BufferView * bv, float sx) const {
209 UpdatableInset::scroll(bv, sx);
212 void scroll(BufferView * bv, int offset) const {
213 UpdatableInset::scroll(bv, offset);
216 void selectAll(BufferView * bv);
218 void clearSelection(BufferView * bv);
220 Paragraph * getParFromID(int id) const;
222 Inset * getInsetFromID(int id) const;
224 Paragraph * firstParagraph() const;
226 Paragraph * getFirstParagraph(int) const;
228 LyXCursor const & cursor(BufferView *) const;
230 Paragraph * paragraph() const;
232 void paragraph(Paragraph *);
234 bool allowSpellcheck() { return true; }
236 string const selectNextWordToSpellcheck(BufferView *,
237 float & value) const;
238 void selectSelectedWord(BufferView *);
240 void toggleSelection(BufferView *, bool kill_selection);
242 bool searchForward(BufferView *, string const &,
243 bool = true, bool = false);
245 bool searchBackward(BufferView *, string const &,
246 bool = true, bool = false);
248 bool checkInsertChar(LyXFont &);
250 void getDrawFont(LyXFont &) const;
252 void appendParagraphs(BufferParams const & bparams, Paragraph *);
255 // Public structures and variables
257 mutable int need_update;
261 void updateLocal(BufferView *, int what, bool mark_dirty) const;
262 /// set parameters for an initial lock of this inset
263 void lockInset(BufferView *);
264 /// lock an inset inside this one
265 void lockInset(BufferView *, UpdatableInset *);
267 mutable int drawTextXOffset;
269 mutable int drawTextYOffset;
273 DrawFrame drawFrame_;
275 LColor::color frame_color;
281 InnerCache(boost::shared_ptr<LyXText>);
283 boost::shared_ptr<LyXText> text;
288 typedef std::map<BufferView *, InnerCache> Cache;
290 typedef Cache::value_type value_type;
292 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
294 UpdatableInset::RESULT moveRight(BufferView *,
295 bool activate_inset = true,
296 bool selecting = false);
298 UpdatableInset::RESULT moveLeft(BufferView *,
299 bool activate_inset = true,
300 bool selecting = false);
302 UpdatableInset::RESULT moveRightIntern(BufferView *, bool front,
303 bool activate_inset = true,
304 bool selecting = false);
306 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool front,
307 bool activate_inset = true,
308 bool selecting = false);
311 UpdatableInset::RESULT moveUp(BufferView *);
313 UpdatableInset::RESULT moveDown(BufferView *);
315 void setCharFont(Buffer const *, int pos, LyXFont const & font);
317 bool checkAndActivateInset(BufferView * bv, bool front);
319 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
322 void removeNewlines();
324 int cx(BufferView *) const;
326 int cix(BufferView *) const;
328 int cy(BufferView *) const;
330 int ciy(BufferView *) const;
332 lyx::pos_type cpos(BufferView *) const;
334 Paragraph * cpar(BufferView *) const;
336 bool cboundary(BufferView *) const;
338 Row * crow(BufferView *) const;
340 void drawFrame(Painter &, bool cleared) const;
342 void clearFrame(Painter &, bool cleared) const;
344 void clearInset(BufferView *, int baseline, bool & cleared) const;
346 void saveLyXTextState(LyXText *) const;
348 void restoreLyXTextState(BufferView *, LyXText *) const;
350 void reinitLyXText() const;
352 void collapseParagraphs(BufferView *) const;
354 /* Private structures and variables */
360 mutable int insetAscent;
362 mutable int insetDescent;
364 mutable int insetWidth;
368 Paragraph * inset_par;
370 lyx::pos_type inset_pos;
378 mutable int old_max_width;
384 UpdatableInset * the_locking_inset;
386 mutable Paragraph * old_par;
390 mutable int last_drawn_width;
392 mutable bool frame_is_visible;
394 mutable BufferView * cached_bview;
396 mutable boost::shared_ptr<LyXText> cached_text;
400 Paragraph * selstartpar;
401 Paragraph * selendpar;
403 lyx::pos_type selstartpos;
404 lyx::pos_type selendpos;
406 bool selstartboundary;
413 mutable save_state sstate;
416 // this is needed globally so we know that we're using it actually and
417 // so the LyXText-Cache is not erased until used!
418 mutable LyXText * lt;
420 // to remember old painted frame dimensions to clear it on the right spot!
427 bool in_update; /* as update is not reentrant! */
428 mutable BufferView * do_resize;
429 mutable bool do_reinit;
430 mutable bool in_insetAllowed;
432 // these are used to check for mouse movement in Motion selection code