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/smart_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
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, unsigned int);
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, int);
128 void insetButtonPress(BufferView *, int, int, int);
130 void insetMotionNotify(BufferView *, int, int, int);
132 void insetKeyPress(XKeyEvent *);
134 UpdatableInset::RESULT localDispatch(BufferView *,
135 kb_action, string const &);
137 int latex(Buffer const *, std::ostream &,
138 bool fragile, bool free_spc) const;
140 int ascii(Buffer const *, std::ostream &, int linelen) const;
142 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
144 int docbook(Buffer const *, std::ostream &) const ;
146 void validate(LaTeXFeatures & features) const;
148 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
150 void getCursorPos(BufferView *, int & x, int & y) const;
152 unsigned int insetInInsetY();
154 void toggleInsetCursor(BufferView *);
156 void showInsetCursor(BufferView *, bool show = true);
158 void hideInsetCursor(BufferView *);
160 void fitInsetCursor(BufferView *) const;
162 bool insertInset(BufferView *, Inset *);
164 bool insetAllowed(Inset::Code) const;
166 UpdatableInset * getLockingInset() const;
168 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
170 void setFont(BufferView *, LyXFont const &,
171 bool toggleall = false,
172 bool selectall = false);
174 int getMaxWidth(BufferView *, UpdatableInset const *) const;
176 void init(InsetText const * ins = 0, bool same_id = false);
178 void writeParagraphData(Buffer const *, std::ostream &) const;
180 void setParagraphData(Paragraph *, bool same_id = false);
182 void setText(string const &);
184 void setAutoBreakRows(bool);
186 bool getAutoBreakRows() const { return autoBreakRows; }
188 void setDrawFrame(BufferView *, DrawFrame);
190 void setFrameColor(BufferView *, LColor::color);
192 LyXText * getLyXText(BufferView const *,
193 bool const recursive = false) const;
195 void deleteLyXText(BufferView *, bool recursive = true) const;
197 void resizeLyXText(BufferView *, bool force = false) const;
199 bool showInsetDialog(BufferView *) const;
201 std::vector<string> const getLabelList() const;
205 int scroll(bool recursive = true) const;
207 void scroll(BufferView * bv, float sx) const {
208 UpdatableInset::scroll(bv, sx);
211 void scroll(BufferView * bv, int offset) const {
212 UpdatableInset::scroll(bv, offset);
215 void selectAll(BufferView * bv);
217 void clearSelection(BufferView * bv);
219 Paragraph * getParFromID(int id) const;
221 Inset * getInsetFromID(int id) const;
223 Paragraph * firstParagraph() const;
225 Paragraph * getFirstParagraph(int) const;
227 LyXCursor const & cursor(BufferView *) const;
229 Paragraph * paragraph() const;
231 void paragraph(Paragraph *);
233 bool allowSpellcheck() { return true; }
235 string const selectNextWordToSpellcheck(BufferView *,
236 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 &);
250 // Public structures and variables
252 mutable int need_update;
256 void updateLocal(BufferView *, int what, bool mark_dirty) const;
258 void lockInset(BufferView *, UpdatableInset *);
260 mutable int drawTextXOffset;
262 mutable int drawTextYOffset;
266 DrawFrame drawFrame_;
268 LColor::color frame_color;
274 InnerCache(boost::shared_ptr<LyXText>);
276 boost::shared_ptr<LyXText> text;
281 typedef std::map<BufferView *, InnerCache> Cache;
283 typedef Cache::value_type value_type;
285 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
287 UpdatableInset::RESULT moveRight(BufferView *,
288 bool activate_inset = true,
289 bool selecting = false);
291 UpdatableInset::RESULT moveLeft(BufferView *,
292 bool activate_inset = true,
293 bool selecting = false);
295 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
296 bool activate_inset = true,
297 bool selecting = false);
299 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
300 bool activate_inset = true,
301 bool selecting = false);
304 UpdatableInset::RESULT moveUp(BufferView *);
306 UpdatableInset::RESULT moveDown(BufferView *);
308 void setCharFont(Buffer const *, int pos, LyXFont const & font);
310 bool checkAndActivateInset(BufferView * bv, bool behind);
312 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
315 void removeNewlines();
317 int cx(BufferView *) const;
319 int cy(BufferView *) const;
321 lyx::pos_type cpos(BufferView *) const;
323 Paragraph * cpar(BufferView *) const;
325 bool cboundary(BufferView *) const;
327 Row * crow(BufferView *) const;
329 void drawFrame(Painter &, bool cleared) const;
331 void clearFrame(Painter &, bool cleared) const;
333 void clearInset(BufferView *, int baseline, bool & cleared) const;
335 void saveLyXTextState(LyXText *) const;
337 void restoreLyXTextState(BufferView *, LyXText *) const;
339 void reinitLyXText() const;
341 void collapseParagraphs(BufferParams const & bparams) const;
343 /* Private structures and variables */
349 mutable int insetAscent;
351 mutable int insetDescent;
353 mutable int insetWidth;
357 Paragraph * inset_par;
359 lyx::pos_type inset_pos;
367 mutable int old_max_width;
373 UpdatableInset * the_locking_inset;
375 mutable Paragraph * old_par;
379 mutable int last_drawn_width;
381 mutable bool frame_is_visible;
383 mutable BufferView * cached_bview;
385 mutable boost::shared_ptr<LyXText> cached_text;
389 Paragraph * selstartpar;
390 Paragraph * selendpar;
392 lyx::pos_type selstartpos;
393 lyx::pos_type selendpos;
395 bool selstartboundary;
402 mutable save_state sstate;
405 // this is needed globally so we know that we're using it actually and
406 // so the LyXText-Cache is not erased until used!
407 mutable LyXText * lt;
409 // to remember old painted frame dimensions to clear it on the right spot!
416 bool in_update; /* as update is not reentrant! */
417 mutable BufferView * do_resize;
418 mutable bool do_reinit;
419 mutable bool in_insetAllowed;