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 bool insetButtonRelease(BufferView *, int, int, mouse_button::state);
130 void insetButtonPress(BufferView *, int, int, mouse_button::state);
132 void insetMotionNotify(BufferView *, int, int, mouse_button::state);
134 UpdatableInset::RESULT localDispatch(BufferView *, FuncRequest const &);
136 int latex(Buffer const *, std::ostream &,
137 bool fragile, bool free_spc) const;
139 int ascii(Buffer const *, std::ostream &, int linelen) const;
141 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
143 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
145 void validate(LaTeXFeatures & features) const;
147 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
149 void getCursorPos(BufferView *, int & x, int & y) const;
151 int insetInInsetY() const;
153 void toggleInsetCursor(BufferView *);
155 void showInsetCursor(BufferView *, bool show = true);
157 void hideInsetCursor(BufferView *);
159 void fitInsetCursor(BufferView *) const;
161 bool insertInset(BufferView *, Inset *);
163 bool insetAllowed(Inset::Code) const;
165 UpdatableInset * getLockingInset() const;
167 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
169 void setFont(BufferView *, LyXFont const &,
170 bool toggleall = false,
171 bool selectall = false);
173 int getMaxWidth(BufferView *, UpdatableInset const *) const;
175 void init(InsetText const * ins = 0, bool same_id = false);
177 void writeParagraphData(Buffer const *, std::ostream &) const;
179 void setParagraphData(Paragraph *, bool same_id = false);
181 void setText(string const &, LyXFont const &);
183 void setAutoBreakRows(bool);
185 bool getAutoBreakRows() const { return autoBreakRows; }
187 void setDrawFrame(BufferView *, DrawFrame);
189 void setFrameColor(BufferView *, LColor::color);
191 LyXText * getLyXText(BufferView const *,
192 bool const recursive = false) const;
194 void deleteLyXText(BufferView *, bool recursive = true) const;
196 void resizeLyXText(BufferView *, bool force = false) const;
198 bool showInsetDialog(BufferView *) const;
200 std::vector<string> const getLabelList() const;
204 int scroll(bool recursive = true) const;
206 void scroll(BufferView * bv, float sx) const {
207 UpdatableInset::scroll(bv, sx);
210 void scroll(BufferView * bv, int offset) const {
211 UpdatableInset::scroll(bv, offset);
214 void selectAll(BufferView * bv);
216 void clearSelection(BufferView * bv);
218 Paragraph * getParFromID(int id) const;
220 Inset * getInsetFromID(int id) const;
222 Paragraph * firstParagraph() const;
224 Paragraph * getFirstParagraph(int) const;
226 LyXCursor const & cursor(BufferView *) const;
228 Paragraph * paragraph() const;
230 void paragraph(Paragraph *);
232 bool allowSpellcheck() { return true; }
235 selectNextWordToSpellcheck(BufferView *, float & value) const;
237 void selectSelectedWord(BufferView *);
239 void toggleSelection(BufferView *, bool kill_selection);
241 bool searchForward(BufferView *, string const &,
242 bool = true, bool = false);
244 bool searchBackward(BufferView *, string const &,
245 bool = true, bool = false);
247 bool checkInsertChar(LyXFont &);
249 void getDrawFont(LyXFont &) const;
251 void appendParagraphs(BufferParams const & bparams, Paragraph *);
253 void addPreview(grfx::PreviewLoader &) const;
256 // Public structures and variables
258 mutable int need_update;
262 void updateLocal(BufferView *, int what, bool mark_dirty) const;
263 /// set parameters for an initial lock of this inset
264 void lockInset(BufferView *);
265 /// lock an inset inside this one
266 void lockInset(BufferView *, UpdatableInset *);
268 mutable int drawTextXOffset;
270 mutable int drawTextYOffset;
274 DrawFrame drawFrame_;
276 LColor::color frame_color;
282 InnerCache(boost::shared_ptr<LyXText>);
284 boost::shared_ptr<LyXText> text;
289 typedef std::map<BufferView *, InnerCache> Cache;
291 typedef Cache::value_type value_type;
293 int beginningOfMainBody(Paragraph * par) const;
295 UpdatableInset::RESULT moveRight(BufferView *,
296 bool activate_inset = true,
297 bool selecting = false);
299 UpdatableInset::RESULT moveLeft(BufferView *,
300 bool activate_inset = true,
301 bool selecting = false);
303 UpdatableInset::RESULT moveRightIntern(BufferView *, bool front,
304 bool activate_inset = true,
305 bool selecting = false);
307 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool front,
308 bool activate_inset = true,
309 bool selecting = false);
312 UpdatableInset::RESULT moveUp(BufferView *);
314 UpdatableInset::RESULT moveDown(BufferView *);
316 void setCharFont(Buffer const *, int pos, LyXFont const & font);
318 bool checkAndActivateInset(BufferView * bv, bool front);
320 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
321 mouse_button::state button = mouse_button::none);
323 void removeNewlines();
325 int cx(BufferView *) const;
327 int cix(BufferView *) const;
329 int cy(BufferView *) const;
331 int ciy(BufferView *) const;
333 lyx::pos_type cpos(BufferView *) const;
335 Paragraph * cpar(BufferView *) const;
337 bool cboundary(BufferView *) const;
339 Row * crow(BufferView *) const;
341 void drawFrame(Painter &, bool cleared) const;
343 void clearFrame(Painter &, bool cleared) const;
345 void clearInset(BufferView *, int baseline, bool & cleared) const;
347 void saveLyXTextState(LyXText *) const;
349 void restoreLyXTextState(BufferView *, LyXText *) const;
351 void reinitLyXText() const;
353 void collapseParagraphs(BufferView *) const;
355 /* Private structures and variables */
357 ParagraphList paragraphs;
361 mutable int insetAscent;
363 mutable int insetDescent;
365 mutable int insetWidth;
369 Paragraph * inset_par;
371 lyx::pos_type inset_pos;
379 mutable int old_max_width;
383 UpdatableInset * the_locking_inset;
385 mutable Paragraph * old_par;
389 mutable int last_drawn_width;
391 mutable bool frame_is_visible;
393 mutable BufferView * cached_bview;
395 mutable boost::shared_ptr<LyXText> cached_text;
399 Paragraph * selstartpar;
400 Paragraph * selendpar;
402 lyx::pos_type selstartpos;
403 lyx::pos_type selendpos;
405 bool selstartboundary;
412 mutable save_state sstate;
415 // this is needed globally so we know that we're using it actually and
416 // so the LyXText-Cache is not erased until used!
417 mutable LyXText * lt;
419 // to remember old painted frame dimensions to clear it on the right spot!
426 bool in_update; /* as update is not reentrant! */
427 mutable BufferView * do_resize;
428 mutable bool do_reinit;
429 mutable bool in_insetAllowed;
431 // these are used to check for mouse movement in Motion selection code