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 "ParagraphList.h"
27 #include "support/types.h"
29 #include <boost/shared_ptr.hpp>
41 A text inset is like a TeX box to write full text
42 (including styles and other insets) in a given space.
45 class InsetText : public UpdatableInset {
48 /// numbers need because of test if codeA < codeB
78 InsetText(BufferParams const &);
81 InsetText(InsetText const &, bool same_id = false);
85 Inset * clone(Buffer const &, bool same_id = false) const;
87 InsetText & operator=(InsetText const & it);
91 void read(Buffer const *, LyXLex &);
93 void write(Buffer const *, std::ostream &) const;
95 int ascent(BufferView *, LyXFont const &) const;
97 int descent(BufferView *, LyXFont const &) const;
99 int width(BufferView *, LyXFont const & f) const;
101 int textWidth(BufferView *, bool fordraw = false) const;
103 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
105 void update(BufferView *, LyXFont const &, bool = false);
107 void setUpdateStatus(BufferView *, int what) const;
109 string const editMessage() const;
111 void edit(BufferView *, int, int, mouse_button::state);
113 void edit(BufferView *, bool front = true);
115 bool isTextInset() const { return true; }
117 bool doClearArea() const;
119 void insetUnlock(BufferView *);
121 bool lockInsetInInset(BufferView *, UpdatableInset *);
123 bool unlockInsetInInset(BufferView *,
124 UpdatableInset *, bool lr = false);
126 bool updateInsetInInset(BufferView *, Inset *);
128 RESULT localDispatch(FuncRequest const &);
130 int latex(Buffer const *, std::ostream &,
131 bool fragile, bool free_spc) const;
133 int ascii(Buffer const *, std::ostream &, int linelen) const;
135 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
137 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
139 void validate(LaTeXFeatures & features) const;
141 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
143 void getCursorPos(BufferView *, int & x, int & y) const;
145 int insetInInsetY() const;
147 void toggleInsetCursor(BufferView *);
149 void showInsetCursor(BufferView *, bool show = true);
151 void hideInsetCursor(BufferView *);
153 void fitInsetCursor(BufferView *) const;
155 bool insertInset(BufferView *, Inset *);
157 bool insetAllowed(Inset::Code) const;
159 UpdatableInset * getLockingInset() const;
161 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
163 void setFont(BufferView *, LyXFont const &,
164 bool toggleall = false,
165 bool selectall = false);
167 int getMaxWidth(BufferView *, UpdatableInset const *) const;
169 void init(InsetText const * ins = 0, bool same_id = false);
171 void writeParagraphData(Buffer const *, std::ostream &) const;
173 void setParagraphData(Paragraph *, bool same_id = false);
175 void setText(string const &, LyXFont const &);
177 void setAutoBreakRows(bool);
179 bool getAutoBreakRows() const { return autoBreakRows; }
181 void setDrawFrame(BufferView *, DrawFrame);
183 void setFrameColor(BufferView *, LColor::color);
185 LyXText * getLyXText(BufferView const *,
186 bool const recursive = false) const;
188 void deleteLyXText(BufferView *, bool recursive = true) const;
190 void resizeLyXText(BufferView *, bool force = false) const;
192 bool showInsetDialog(BufferView *) const;
194 std::vector<string> const getLabelList() const;
198 int scroll(bool recursive = true) const;
200 void scroll(BufferView * bv, float sx) const {
201 UpdatableInset::scroll(bv, sx);
204 void scroll(BufferView * bv, int offset) const {
205 UpdatableInset::scroll(bv, offset);
208 void selectAll(BufferView * bv);
210 void clearSelection(BufferView * bv);
212 Paragraph * getParFromID(int id) const;
214 Inset * getInsetFromID(int id) const;
216 Paragraph * firstParagraph() const;
218 Paragraph * getFirstParagraph(int) const;
220 LyXCursor const & cursor(BufferView *) const;
222 Paragraph * paragraph() const;
224 void paragraph(Paragraph *);
226 bool allowSpellcheck() { return true; }
229 selectNextWordToSpellcheck(BufferView *, float & value) const;
231 void selectSelectedWord(BufferView *);
233 void toggleSelection(BufferView *, bool kill_selection);
235 bool searchForward(BufferView *, string const &,
236 bool = true, bool = false);
238 bool searchBackward(BufferView *, string const &,
239 bool = true, bool = false);
241 bool checkInsertChar(LyXFont &);
243 void getDrawFont(LyXFont &) const;
245 void appendParagraphs(BufferParams const & bparams, Paragraph *);
247 void addPreview(grfx::PreviewLoader &) const;
250 // Public structures and variables
252 mutable int need_update;
256 void updateLocal(BufferView *, int what, bool mark_dirty) const;
257 /// set parameters for an initial lock of this inset
258 void lockInset(BufferView *);
259 /// lock an inset inside this one
260 void lockInset(BufferView *, UpdatableInset *);
262 mutable int drawTextXOffset;
264 mutable int drawTextYOffset;
268 DrawFrame drawFrame_;
270 LColor::color frame_color;
274 void lfunMousePress(FuncRequest const &);
276 bool lfunMouseRelease(FuncRequest const &);
278 void lfunMouseMotion(FuncRequest const &);
283 InnerCache(boost::shared_ptr<LyXText>);
285 boost::shared_ptr<LyXText> text;
290 typedef std::map<BufferView *, InnerCache> Cache;
292 typedef Cache::value_type value_type;
294 int beginningOfMainBody(Paragraph * par) const;
296 RESULT moveRight(BufferView *,
297 bool activate_inset = true,
298 bool selecting = false);
300 RESULT moveLeft(BufferView *,
301 bool activate_inset = true,
302 bool selecting = false);
304 RESULT moveRightIntern(BufferView *, bool front,
305 bool activate_inset = true,
306 bool selecting = false);
308 RESULT moveLeftIntern(BufferView *, bool front,
309 bool activate_inset = true,
310 bool selecting = false);
313 RESULT moveUp(BufferView *);
315 RESULT moveDown(BufferView *);
317 void setCharFont(Buffer const *, int pos, LyXFont const & font);
319 bool checkAndActivateInset(BufferView * bv, bool front);
321 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
322 mouse_button::state button = mouse_button::none);
324 void removeNewlines();
326 int cx(BufferView *) const;
328 int cix(BufferView *) const;
330 int cy(BufferView *) const;
332 int ciy(BufferView *) const;
334 lyx::pos_type cpos(BufferView *) const;
336 Paragraph * cpar(BufferView *) const;
338 bool cboundary(BufferView *) const;
340 Row * crow(BufferView *) const;
342 void drawFrame(Painter &, bool cleared) const;
344 void clearFrame(Painter &, bool cleared) const;
346 void clearInset(BufferView *, int baseline, bool & cleared) const;
348 void saveLyXTextState(LyXText *) const;
350 void restoreLyXTextState(BufferView *, LyXText *) const;
352 void reinitLyXText() const;
354 void collapseParagraphs(BufferView *) const;
356 /* Private structures and variables */
358 ParagraphList paragraphs;
362 mutable int insetAscent;
364 mutable int insetDescent;
366 mutable int insetWidth;
370 Paragraph * inset_par;
372 lyx::pos_type inset_pos;
380 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