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 "support/types.h"
27 #include <boost/shared_ptr.hpp>
39 A text inset is like a TeX box to write full text
40 (including styles and other insets) in a given space.
43 class InsetText : public UpdatableInset {
46 /// numbers need because of test if codeA < codeB
76 InsetText(BufferParams const &);
79 InsetText(InsetText const &, bool same_id = false);
83 Inset * clone(Buffer const &, bool same_id = false) const;
85 InsetText & operator=(InsetText const & it);
89 void read(Buffer const *, LyXLex &);
91 void write(Buffer const *, std::ostream &) const;
93 int ascent(BufferView *, LyXFont const &) const;
95 int descent(BufferView *, LyXFont const &) const;
97 int width(BufferView *, LyXFont const & f) const;
99 int textWidth(BufferView *, bool fordraw = false) const;
101 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
103 void update(BufferView *, LyXFont const &, bool = false);
105 void setUpdateStatus(BufferView *, int what) const;
107 string const editMessage() const;
109 void edit(BufferView *, int, int, mouse_button::state);
111 void edit(BufferView *, bool front = true);
113 bool isTextInset() const { return true; }
115 bool doClearArea() const;
117 void insetUnlock(BufferView *);
119 bool lockInsetInInset(BufferView *, UpdatableInset *);
121 bool unlockInsetInInset(BufferView *,
122 UpdatableInset *, bool lr = false);
124 bool updateInsetInInset(BufferView *, Inset *);
126 bool insetButtonRelease(BufferView *, int, int, mouse_button::state);
128 void insetButtonPress(BufferView *, int, int, mouse_button::state);
130 void insetMotionNotify(BufferView *, int, int, mouse_button::state);
132 UpdatableInset::RESULT localDispatch(BufferView *, FuncRequest 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 &, bool mixcont) 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 int insetInInsetY() const;
151 void toggleInsetCursor(BufferView *);
153 void showInsetCursor(BufferView *, bool show = true);
155 void hideInsetCursor(BufferView *);
157 void fitInsetCursor(BufferView *) const;
159 bool insertInset(BufferView *, Inset *);
161 bool insetAllowed(Inset::Code) const;
163 UpdatableInset * getLockingInset() const;
165 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
167 void setFont(BufferView *, LyXFont const &,
168 bool toggleall = false,
169 bool selectall = false);
171 int getMaxWidth(BufferView *, UpdatableInset const *) const;
173 void init(InsetText const * ins = 0, bool same_id = false);
175 void writeParagraphData(Buffer const *, std::ostream &) const;
177 void setParagraphData(Paragraph *, bool same_id = false);
179 void setText(string const &, LyXFont const &);
181 void setAutoBreakRows(bool);
183 bool getAutoBreakRows() const { return autoBreakRows; }
185 void setDrawFrame(BufferView *, DrawFrame);
187 void setFrameColor(BufferView *, LColor::color);
189 LyXText * getLyXText(BufferView const *,
190 bool const recursive = false) const;
192 void deleteLyXText(BufferView *, bool recursive = true) const;
194 void resizeLyXText(BufferView *, bool force = false) const;
196 bool showInsetDialog(BufferView *) const;
198 std::vector<string> const getLabelList() const;
202 int scroll(bool recursive = true) const;
204 void scroll(BufferView * bv, float sx) const {
205 UpdatableInset::scroll(bv, sx);
208 void scroll(BufferView * bv, int offset) const {
209 UpdatableInset::scroll(bv, offset);
212 void selectAll(BufferView * bv);
214 void clearSelection(BufferView * bv);
216 Paragraph * getParFromID(int id) const;
218 Inset * getInsetFromID(int id) const;
220 Paragraph * firstParagraph() const;
222 Paragraph * getFirstParagraph(int) const;
224 LyXCursor const & cursor(BufferView *) const;
226 Paragraph * paragraph() const;
228 void paragraph(Paragraph *);
230 bool allowSpellcheck() { return true; }
232 WordLangTuple selectNextWordToSpellcheck(BufferView *,
233 float & value) const;
234 void selectSelectedWord(BufferView *);
236 void toggleSelection(BufferView *, bool kill_selection);
238 bool searchForward(BufferView *, string const &,
239 bool = true, bool = false);
241 bool searchBackward(BufferView *, string const &,
242 bool = true, bool = false);
244 bool checkInsertChar(LyXFont &);
246 void getDrawFont(LyXFont &) const;
248 void appendParagraphs(BufferParams const & bparams, Paragraph *);
250 void addPreview(grfx::PreviewLoader &) const;
253 // Public structures and variables
255 mutable int need_update;
259 void updateLocal(BufferView *, int what, bool mark_dirty) const;
260 /// set parameters for an initial lock of this inset
261 void lockInset(BufferView *);
262 /// lock an inset inside this one
263 void lockInset(BufferView *, UpdatableInset *);
265 mutable int drawTextXOffset;
267 mutable int drawTextYOffset;
271 DrawFrame drawFrame_;
273 LColor::color frame_color;
279 InnerCache(boost::shared_ptr<LyXText>);
281 boost::shared_ptr<LyXText> text;
286 typedef std::map<BufferView *, InnerCache> Cache;
288 typedef Cache::value_type value_type;
290 int beginningOfMainBody(Paragraph * par) const;
292 UpdatableInset::RESULT moveRight(BufferView *,
293 bool activate_inset = true,
294 bool selecting = false);
296 UpdatableInset::RESULT moveLeft(BufferView *,
297 bool activate_inset = true,
298 bool selecting = false);
300 UpdatableInset::RESULT moveRightIntern(BufferView *, bool front,
301 bool activate_inset = true,
302 bool selecting = false);
304 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool front,
305 bool activate_inset = true,
306 bool selecting = false);
309 UpdatableInset::RESULT moveUp(BufferView *);
311 UpdatableInset::RESULT moveDown(BufferView *);
313 void setCharFont(Buffer const *, int pos, LyXFont const & font);
315 bool checkAndActivateInset(BufferView * bv, bool front);
317 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
318 mouse_button::state button = mouse_button::none);
320 void removeNewlines();
322 int cx(BufferView *) const;
324 int cix(BufferView *) const;
326 int cy(BufferView *) const;
328 int ciy(BufferView *) const;
330 lyx::pos_type cpos(BufferView *) const;
332 Paragraph * cpar(BufferView *) const;
334 bool cboundary(BufferView *) const;
336 Row * crow(BufferView *) const;
338 void drawFrame(Painter &, bool cleared) const;
340 void clearFrame(Painter &, bool cleared) const;
342 void clearInset(BufferView *, int baseline, bool & cleared) const;
344 void saveLyXTextState(LyXText *) const;
346 void restoreLyXTextState(BufferView *, LyXText *) const;
348 void reinitLyXText() const;
350 void collapseParagraphs(BufferView *) const;
352 /* Private structures and variables */
358 mutable int insetAscent;
360 mutable int insetDescent;
362 mutable int insetWidth;
366 Paragraph * inset_par;
368 lyx::pos_type inset_pos;
376 mutable int old_max_width;
380 UpdatableInset * the_locking_inset;
382 mutable Paragraph * old_par;
386 mutable int last_drawn_width;
388 mutable bool frame_is_visible;
390 mutable BufferView * cached_bview;
392 mutable boost::shared_ptr<LyXText> cached_text;
396 Paragraph * selstartpar;
397 Paragraph * selendpar;
399 lyx::pos_type selstartpos;
400 lyx::pos_type selendpos;
402 bool selstartboundary;
409 mutable save_state sstate;
412 // this is needed globally so we know that we're using it actually and
413 // so the LyXText-Cache is not erased until used!
414 mutable LyXText * lt;
416 // to remember old painted frame dimensions to clear it on the right spot!
423 bool in_update; /* as update is not reentrant! */
424 mutable BufferView * do_resize;
425 mutable bool do_reinit;
426 mutable bool in_insetAllowed;
428 // these are used to check for mouse movement in Motion selection code