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 &);
249 void getDrawFont(LyXFont &) const;
252 // Public structures and variables
254 mutable int need_update;
258 void updateLocal(BufferView *, int what, bool mark_dirty) const;
260 void lockInset(BufferView *, UpdatableInset *);
262 mutable int drawTextXOffset;
264 mutable int drawTextYOffset;
268 DrawFrame drawFrame_;
270 LColor::color frame_color;
276 InnerCache(boost::shared_ptr<LyXText>);
278 boost::shared_ptr<LyXText> text;
283 typedef std::map<BufferView *, InnerCache> Cache;
285 typedef Cache::value_type value_type;
287 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
289 UpdatableInset::RESULT moveRight(BufferView *,
290 bool activate_inset = true,
291 bool selecting = false);
293 UpdatableInset::RESULT moveLeft(BufferView *,
294 bool activate_inset = true,
295 bool selecting = false);
297 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
298 bool activate_inset = true,
299 bool selecting = false);
301 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
302 bool activate_inset = true,
303 bool selecting = false);
306 UpdatableInset::RESULT moveUp(BufferView *);
308 UpdatableInset::RESULT moveDown(BufferView *);
310 void setCharFont(Buffer const *, int pos, LyXFont const & font);
312 bool checkAndActivateInset(BufferView * bv, bool behind);
314 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
317 void removeNewlines();
319 int cx(BufferView *) const;
321 int cy(BufferView *) const;
323 lyx::pos_type cpos(BufferView *) const;
325 Paragraph * cpar(BufferView *) const;
327 bool cboundary(BufferView *) const;
329 Row * crow(BufferView *) const;
331 void drawFrame(Painter &, bool cleared) const;
333 void clearFrame(Painter &, bool cleared) const;
335 void clearInset(BufferView *, int baseline, bool & cleared) const;
337 void saveLyXTextState(LyXText *) const;
339 void restoreLyXTextState(BufferView *, LyXText *) const;
341 void reinitLyXText() const;
343 void collapseParagraphs(BufferParams const & bparams) const;
345 /* Private structures and variables */
351 mutable int insetAscent;
353 mutable int insetDescent;
355 mutable int insetWidth;
359 Paragraph * inset_par;
361 lyx::pos_type inset_pos;
369 mutable int old_max_width;
375 UpdatableInset * the_locking_inset;
377 mutable Paragraph * old_par;
381 mutable int last_drawn_width;
383 mutable bool frame_is_visible;
385 mutable BufferView * cached_bview;
387 mutable boost::shared_ptr<LyXText> cached_text;
391 Paragraph * selstartpar;
392 Paragraph * selendpar;
394 lyx::pos_type selstartpos;
395 lyx::pos_type selendpos;
397 bool selstartboundary;
404 mutable save_state sstate;
407 // this is needed globally so we know that we're using it actually and
408 // so the LyXText-Cache is not erased until used!
409 mutable LyXText * lt;
411 // to remember old painted frame dimensions to clear it on the right spot!
418 bool in_update; /* as update is not reentrant! */
419 mutable BufferView * do_resize;
420 mutable bool do_reinit;
421 mutable bool in_insetAllowed;
423 // these are used to check for mouse movement in Motion selection code