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 *,
133 kb_action, string const &);
135 int latex(Buffer const *, std::ostream &,
136 bool fragile, bool free_spc) const;
138 int ascii(Buffer const *, std::ostream &, int linelen) const;
140 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
142 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
144 void validate(LaTeXFeatures & features) const;
146 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
148 void getCursorPos(BufferView *, int & x, int & y) const;
150 int insetInInsetY() const;
152 void toggleInsetCursor(BufferView *);
154 void showInsetCursor(BufferView *, bool show = true);
156 void hideInsetCursor(BufferView *);
158 void fitInsetCursor(BufferView *) const;
160 bool insertInset(BufferView *, Inset *);
162 bool insetAllowed(Inset::Code) const;
164 UpdatableInset * getLockingInset() const;
166 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
168 void setFont(BufferView *, LyXFont const &,
169 bool toggleall = false,
170 bool selectall = false);
172 int getMaxWidth(BufferView *, UpdatableInset const *) const;
174 void init(InsetText const * ins = 0, bool same_id = false);
176 void writeParagraphData(Buffer const *, std::ostream &) const;
178 void setParagraphData(Paragraph *, bool same_id = false);
180 void setText(string const &, LyXFont const &);
182 void setAutoBreakRows(bool);
184 bool getAutoBreakRows() const { return autoBreakRows; }
186 void setDrawFrame(BufferView *, DrawFrame);
188 void setFrameColor(BufferView *, LColor::color);
190 LyXText * getLyXText(BufferView const *,
191 bool const recursive = false) const;
193 void deleteLyXText(BufferView *, bool recursive = true) const;
195 void resizeLyXText(BufferView *, bool force = false) const;
197 bool showInsetDialog(BufferView *) const;
199 std::vector<string> const getLabelList() const;
203 int scroll(bool recursive = true) const;
205 void scroll(BufferView * bv, float sx) const {
206 UpdatableInset::scroll(bv, sx);
209 void scroll(BufferView * bv, int offset) const {
210 UpdatableInset::scroll(bv, offset);
213 void selectAll(BufferView * bv);
215 void clearSelection(BufferView * bv);
217 Paragraph * getParFromID(int id) const;
219 Inset * getInsetFromID(int id) const;
221 Paragraph * firstParagraph() const;
223 Paragraph * getFirstParagraph(int) const;
225 LyXCursor const & cursor(BufferView *) const;
227 Paragraph * paragraph() const;
229 void paragraph(Paragraph *);
231 bool allowSpellcheck() { return true; }
233 string const selectNextWordToSpellcheck(BufferView *,
234 float & value) const;
235 void selectSelectedWord(BufferView *);
237 void toggleSelection(BufferView *, bool kill_selection);
239 bool searchForward(BufferView *, string const &,
240 bool = true, bool = false);
242 bool searchBackward(BufferView *, string const &,
243 bool = true, bool = false);
245 bool checkInsertChar(LyXFont &);
247 void getDrawFont(LyXFont &) const;
249 void appendParagraphs(BufferParams const & bparams, Paragraph *);
251 void addPreview(grfx::PreviewLoader &) const;
254 // Public structures and variables
256 mutable int need_update;
260 void updateLocal(BufferView *, int what, bool mark_dirty) const;
261 /// set parameters for an initial lock of this inset
262 void lockInset(BufferView *);
263 /// lock an inset inside this one
264 void lockInset(BufferView *, UpdatableInset *);
266 mutable int drawTextXOffset;
268 mutable int drawTextYOffset;
272 DrawFrame drawFrame_;
274 LColor::color frame_color;
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 UpdatableInset::RESULT moveRight(BufferView *,
294 bool activate_inset = true,
295 bool selecting = false);
297 UpdatableInset::RESULT moveLeft(BufferView *,
298 bool activate_inset = true,
299 bool selecting = false);
301 UpdatableInset::RESULT moveRightIntern(BufferView *, bool front,
302 bool activate_inset = true,
303 bool selecting = false);
305 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool front,
306 bool activate_inset = true,
307 bool selecting = false);
310 UpdatableInset::RESULT moveUp(BufferView *);
312 UpdatableInset::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 */
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;
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