4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
15 #include "updatableinset.h"
16 #include "textcursor.h"
19 #include "ParagraphList.h"
21 #include "dimension.h"
22 #include "frontends/mouse_state.h"
24 #include "support/types.h"
26 #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
74 InsetText(BufferParams const &);
76 explicit InsetText(InsetText const &);
78 InsetBase * clone() const;
80 InsetText & operator=(InsetText const & it);
81 /// empty inset to empty par, or just mark as erased
82 void clear(bool just_mark_erased);
84 void read(Buffer const *, LyXLex &);
86 void write(Buffer const *, std::ostream &) const;
88 void metrics(MetricsInfo &, Dimension &) const;
90 int textWidth(BufferView *, bool fordraw = false) const;
92 void draw(PainterInfo & pi, int x, int y) const;
94 void update(BufferView *, bool = false);
96 void setUpdateStatus(BufferView *, int what) const;
98 string const editMessage() const;
100 bool isTextInset() const { return true; }
102 void insetUnlock(BufferView *);
104 bool lockInsetInInset(BufferView *, UpdatableInset *);
106 bool unlockInsetInInset(BufferView *,
107 UpdatableInset *, bool lr = false);
109 bool updateInsetInInset(BufferView *, Inset *);
111 RESULT localDispatch(FuncRequest const &);
113 int latex(Buffer const *, std::ostream &,
114 LatexRunParams const &) const;
116 int ascii(Buffer const *, std::ostream &, int linelen) const;
118 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
120 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
122 void validate(LaTeXFeatures & features) const;
124 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
126 void getCursorPos(BufferView *, int & x, int & y) const;
127 /// Get the absolute document x,y of the cursor
128 virtual void getCursor(BufferView &, int &, int &) const;
130 int insetInInsetY() const;
132 void fitInsetCursor(BufferView *) const;
134 bool insertInset(BufferView *, Inset *);
136 bool insetAllowed(Inset::Code) const;
138 UpdatableInset * getLockingInset() const;
140 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
142 void setFont(BufferView *, LyXFont const &,
143 bool toggleall = false,
144 bool selectall = false);
146 int getMaxWidth(BufferView *, UpdatableInset const *) const;
148 void init(InsetText const * ins);
150 void writeParagraphData(Buffer const *, std::ostream &) const;
152 void setParagraphData(ParagraphList const &);
154 void setText(string const &, LyXFont const &);
156 void setAutoBreakRows(bool);
158 bool getAutoBreakRows() const { return autoBreakRows; }
160 void setDrawFrame(BufferView *, DrawFrame);
162 void setFrameColor(BufferView *, LColor::color);
164 LyXText * getLyXText(BufferView const *,
165 bool const recursive = false) const;
167 void deleteLyXText(BufferView *, bool recursive = true) const;
169 void resizeLyXText(BufferView *, bool force = false) const;
171 bool showInsetDialog(BufferView *) const;
173 void getLabelList(std::vector<string> &) const;
177 int scroll(bool recursive = true) const;
179 void scroll(BufferView * bv, float sx) const {
180 UpdatableInset::scroll(bv, sx);
183 void scroll(BufferView * bv, int offset) const {
184 UpdatableInset::scroll(bv, offset);
187 void selectAll(BufferView * bv);
189 void clearSelection(BufferView * bv);
191 Inset * getInsetFromID(int id) const;
193 ParagraphList * getParagraphs(int) const;
195 LyXCursor const & cursor(BufferView *) const;
197 bool allowSpellcheck() const { return true; }
200 selectNextWordToSpellcheck(BufferView *, float & value) const;
202 void selectSelectedWord(BufferView *);
204 void toggleSelection(BufferView *, bool kill_selection);
206 /// mark as erased for change tracking
207 void markErased() { clear(true); };
209 * Mark as new. Used when pasting in tabular, and adding rows
210 * or columns. Note that pasting will ensure that tracking already
211 * happens, and this just resets the changes for the copied text,
212 * whereas for row/col add, we need to start tracking changes
213 * for the (empty) paragraph contained.
215 void markNew(bool track_changes = false);
217 bool nextChange(BufferView *, lyx::pos_type & length);
220 bool searchForward(BufferView *, string const &,
221 bool = true, bool = false);
223 bool searchBackward(BufferView *, string const &,
224 bool = true, bool = false);
226 bool checkInsertChar(LyXFont &);
228 void getDrawFont(LyXFont &) const;
229 /// append text onto the existing text
230 void appendParagraphs(Buffer * bp, ParagraphList &);
233 void addPreview(grfx::PreviewLoader &) const;
236 // Public structures and variables
238 mutable int need_update;
240 bool haveParagraphs() const {
244 ParagraphList paragraphs;
247 void updateLocal(BufferView *, int what, bool mark_dirty);
248 /// set parameters for an initial lock of this inset
249 void lockInset(BufferView *);
250 /// lock an inset inside this one
251 void lockInset(BufferView *, UpdatableInset *);
253 mutable int drawTextXOffset;
255 mutable int drawTextYOffset;
259 DrawFrame drawFrame_;
261 LColor::color frame_color;
265 void lfunMousePress(FuncRequest const &);
267 bool lfunMouseRelease(FuncRequest const &);
269 void lfunMouseMotion(FuncRequest const &);
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 RESULT moveRight(BufferView *,
286 bool activate_inset = true,
287 bool selecting = false);
289 RESULT moveLeft(BufferView *,
290 bool activate_inset = true,
291 bool selecting = false);
293 RESULT moveRightIntern(BufferView *, bool front,
294 bool activate_inset = true,
295 bool selecting = false);
297 RESULT moveLeftIntern(BufferView *, bool front,
298 bool activate_inset = true,
299 bool selecting = false);
302 RESULT moveUp(BufferView *);
304 RESULT moveDown(BufferView *);
306 void setCharFont(Buffer const *, int pos, LyXFont const & font);
308 bool checkAndActivateInset(BufferView * bv, bool front);
310 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
311 mouse_button::state button = mouse_button::none);
313 void removeNewlines();
315 int cx(BufferView *) const;
317 int cix(BufferView *) const;
319 int cy(BufferView *) const;
321 int ciy(BufferView *) const;
323 lyx::pos_type cpos(BufferView *) const;
325 ParagraphList::iterator cpar(BufferView *) const;
327 bool cboundary(BufferView *) const;
329 RowList::iterator crow(BufferView *) const;
331 void drawFrame(Painter &, int x) const;
333 void clearInset(BufferView *, int start_x, int baseline) const;
335 void saveLyXTextState(LyXText *) const;
337 void restoreLyXTextState(LyXText *) const;
339 void reinitLyXText() const;
341 void collapseParagraphs(BufferView *);
343 /* Private structures and variables */
347 mutable Dimension dim_;
351 ParagraphList::iterator inset_par;
353 lyx::pos_type inset_pos;
361 mutable int old_max_width;
365 UpdatableInset * the_locking_inset;
367 mutable ParagraphList::iterator old_par;
371 mutable int last_drawn_width;
373 mutable BufferView * cached_bview;
375 mutable boost::shared_ptr<LyXText> cached_text;
377 /// some funny 'temporarily saved state'
378 mutable TextCursor sstate;
381 // this is needed globally so we know that we're using it actually and
382 // so the LyXText-Cache is not erased until used!
383 mutable LyXText * lt;
385 // to remember old painted frame dimensions to clear it on the right spot!
392 bool in_update; /* as update is not reentrant! */
393 mutable BufferView * do_resize;
394 mutable bool do_reinit;
395 mutable bool in_insetAllowed;
397 // these are used to check for mouse movement in Motion selection code