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/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 &) 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 *);
252 // Public structures and variables
254 mutable int need_update;
258 void updateLocal(BufferView *, int what, bool mark_dirty) const;
259 /// set parameters for an initial lock of this inset
260 void lockInset(BufferView *);
261 /// lock an inset inside this one
262 void lockInset(BufferView *, UpdatableInset *);
264 mutable int drawTextXOffset;
266 mutable int drawTextYOffset;
270 DrawFrame drawFrame_;
272 LColor::color frame_color;
278 InnerCache(boost::shared_ptr<LyXText>);
280 boost::shared_ptr<LyXText> text;
285 typedef std::map<BufferView *, InnerCache> Cache;
287 typedef Cache::value_type value_type;
289 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
291 UpdatableInset::RESULT moveRight(BufferView *,
292 bool activate_inset = true,
293 bool selecting = false);
295 UpdatableInset::RESULT moveLeft(BufferView *,
296 bool activate_inset = true,
297 bool selecting = false);
299 UpdatableInset::RESULT moveRightIntern(BufferView *, bool front,
300 bool activate_inset = true,
301 bool selecting = false);
303 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool front,
304 bool activate_inset = true,
305 bool selecting = false);
308 UpdatableInset::RESULT moveUp(BufferView *);
310 UpdatableInset::RESULT moveDown(BufferView *);
312 void setCharFont(Buffer const *, int pos, LyXFont const & font);
314 bool checkAndActivateInset(BufferView * bv, bool front);
316 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
317 mouse_button::state button = mouse_button::none);
319 void removeNewlines();
321 int cx(BufferView *) const;
323 int cix(BufferView *) const;
325 int cy(BufferView *) const;
327 int ciy(BufferView *) const;
329 lyx::pos_type cpos(BufferView *) const;
331 Paragraph * cpar(BufferView *) const;
333 bool cboundary(BufferView *) const;
335 Row * crow(BufferView *) const;
337 void drawFrame(Painter &, bool cleared) const;
339 void clearFrame(Painter &, bool cleared) const;
341 void clearInset(BufferView *, int baseline, bool & cleared) const;
343 void saveLyXTextState(LyXText *) const;
345 void restoreLyXTextState(BufferView *, LyXText *) const;
347 void reinitLyXText() const;
349 void collapseParagraphs(BufferView *) const;
351 /* Private structures and variables */
357 mutable int insetAscent;
359 mutable int insetDescent;
361 mutable int insetWidth;
365 Paragraph * inset_par;
367 lyx::pos_type inset_pos;
375 mutable int old_max_width;
381 UpdatableInset * the_locking_inset;
383 mutable Paragraph * old_par;
387 mutable int last_drawn_width;
389 mutable bool frame_is_visible;
391 mutable BufferView * cached_bview;
393 mutable boost::shared_ptr<LyXText> cached_text;
397 Paragraph * selstartpar;
398 Paragraph * selendpar;
400 lyx::pos_type selstartpos;
401 lyx::pos_type selendpos;
403 bool selstartboundary;
410 mutable save_state sstate;
413 // this is needed globally so we know that we're using it actually and
414 // so the LyXText-Cache is not erased until used!
415 mutable LyXText * lt;
417 // to remember old painted frame dimensions to clear it on the right spot!
424 bool in_update; /* as update is not reentrant! */
425 mutable BufferView * do_resize;
426 mutable bool do_reinit;
427 mutable bool in_insetAllowed;
429 // these are used to check for mouse movement in Motion selection code