4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
11 * Full author contact details are available in file CREDITS.
17 #include "bufferview_funcs.h"
20 #include "ParagraphList_fwd.h"
21 #include "RowList_fwd.h"
22 #include "textcursor.h"
24 #include "insets/inset.h"
43 This class used to hold the mapping between buffer paragraphs and
44 screen rows. Nowadays, the Paragraphs take care of their rows
45 themselves and this contains just most of the code for manipulating
46 them and interaction with the Cursor.
49 // The inheritance from TextCursor should go. It's just there to ease
51 class LyXText : public TextCursor {
54 LyXText(BufferView *, InsetText *, bool ininset,
55 ParagraphList & paragraphs);
57 void init(BufferView *);
62 /// the current font settings
65 LyXFont real_current_font;
66 /// our buffer's default layout font
69 /// offset of dran area to document start.
72 /// update all cached row positions
73 void updateRowPositions();
75 InsetText * inset_owner;
77 UpdatableInset * the_locking_inset;
80 int getRealCursorX() const;
82 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
84 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
86 LyXFont getLabelFont(ParagraphList::iterator pit) const;
88 void setCharFont(ParagraphList::iterator pit,
89 lyx::pos_type pos, LyXFont const & font);
90 void setCharFont(ParagraphList::iterator pit,
92 LyXFont const & font, bool toggleall);
94 /// what you expect when pressing <enter> at cursor position
95 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
97 /** set layout over selection and make a total rebreak of
100 ParagraphList::iterator
101 setLayout(LyXCursor & actual_cursor,
102 LyXCursor & selection_start,
103 LyXCursor & selection_end,
104 std::string const & layout);
106 void setLayout(std::string const & layout);
109 * Increase or decrease the nesting depth of the selected paragraph(s)
110 * if test_only, don't change any depths. Returns whether something
111 * (would have) changed
113 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
115 /// get the depth at current cursor position
116 int getDepth() const;
118 /** set font over selection and make a total rebreak of those
120 toggleall defaults to false.
122 void setFont(LyXFont const &, bool toggleall = false);
124 /// rebreaks all paragaphs between the given pars.
125 int redoParagraphs(ParagraphList::iterator begin,
126 ParagraphList::iterator end);
127 /// rebreaks the given par
128 void redoParagraph(ParagraphList::iterator pit);
130 /// rebreaks the cursor par
131 void redoParagraph();
133 /// rebreaks the given par, return max row width
134 int redoParagraphInternal(ParagraphList::iterator pit);
138 void toggleFree(LyXFont const &, bool toggleall = false);
141 std::string getStringToIndex();
143 /** insert a character, moves all the following breaks in the
144 same Paragraph one to the right and make a little rebreak
146 void insertChar(char c);
148 void insertInset(InsetOld * inset);
150 /// a full rebreak of the whole text
152 /// compute text metrics
153 void metrics(MetricsInfo & mi, Dimension & dim);
156 InsetOld::RESULT dispatch(FuncRequest const & cmd);
160 BufferView * bv() const;
162 friend class LyXScreen;
165 /// only the top-level LyXText has this non-zero
166 BufferView * bv_owner;
169 /// returns a pointer to a specified row.
171 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
173 /// returns an iterator pointing to a cursor row
174 RowList::iterator getRow(LyXCursor const & cursor) const;
176 RowList::iterator cursorRow() const;
177 /// returns an iterator pointing to a cursor paragraph
178 ParagraphList::iterator getPar(LyXCursor const & cursor) const;
180 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
182 int parOffset(ParagraphList::iterator pit) const;
184 ParagraphList::iterator cursorPar() const;
186 * Return the next row, when cursor is at the end of the
187 * previous row, for insets that take a full row.
189 * FIXME: explain why we need this ? especially for y...
191 RowList::iterator cursorIRow() const;
193 /** returns a pointer to the row near the specified y-coordinate
194 (relative to the whole text). y is set to the real beginning
197 RowList::iterator getRowNearY(int y,
198 ParagraphList::iterator & pit) const;
200 /** returns the column near the specified x-coordinate of the row
201 x is set to the real beginning of this column
203 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
204 RowList::iterator rit, int & x, bool & boundary) const;
206 /// need the selection cursor:
209 void clearSelection();
211 /// select the word we need depending on word_location
212 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
213 /// just selects the word the cursor is in
214 void selectWord(lyx::word_location loc);
215 /// returns the inset at cursor (if it exists), 0 otherwise
216 InsetOld * getInset() const;
218 /// accept selected change
221 /// reject selected change
224 /** 'selects" the next word, where the cursor is not in
225 and returns this word as string. THe cursor will be moved
226 to the beginning of this word.
227 With SelectSelectedWord can this be highlighted really
229 WordLangTuple const selectNextWordToSpellcheck(float & value);
231 void selectSelectedWord();
232 /// re-computes the cached coordinates in the cursor
235 void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
236 /// returns true if par was empty and was removed
237 bool setCursor(lyx::paroffset_type par,
240 bool boundary = false);
242 void setCursor(LyXCursor &, lyx::paroffset_type par,
244 bool boundary = false);
246 void setCursorIntern(lyx::paroffset_type par,
249 bool boundary = false);
251 void setCurrentFont();
254 bool isBoundary(Buffer const &, Paragraph const & par,
255 lyx::pos_type pos) const;
257 bool isBoundary(Buffer const &, Paragraph const & par,
259 LyXFont const & font) const;
262 void setCursorFromCoordinates(int x, int y);
264 void setCursorFromCoordinates(LyXCursor &,
267 void cursorUp(bool selecting = false);
269 void cursorDown(bool selecting = false);
271 void cursorLeft(bool internal = true);
273 void cursorRight(bool internal = true);
275 void cursorLeftOneWord();
277 void cursorRightOneWord();
279 void cursorUpParagraph();
281 void cursorDownParagraph();
287 void cursorPrevious();
299 bool selectWordWhenUnderCursor(lyx::word_location);
305 text_capitalization = 1,
309 /// Change the case of the word at cursor position.
310 void changeCase(TextCase action);
315 void cutSelection(bool doclear = true, bool realcut = true);
317 void copySelection();
319 void pasteSelection(size_t sel_index = 0);
321 /** the DTP switches for paragraphs. LyX will store the top settings
322 always in the first physical paragraph, the bottom settings in the
323 last. When a paragraph is broken, the top settings rest, the bottom
324 settings are given to the new one. So I can make shure, they do not
325 duplicate themself (and you cannnot make dirty things with them! )
327 void setParagraph(bool line_top, bool line_bottom,
328 bool pagebreak_top, bool pagebreak_bottom,
329 VSpace const & space_top,
330 VSpace const & space_bottom,
331 Spacing const & spacing,
333 std::string const & labelwidthstring,
336 /* these things are for search and replace */
339 * Sets the selection from the current cursor position to length
340 * characters to the right. No safety checks.
342 void setSelectionRange(lyx::pos_type length);
344 /** simple replacing. The font of the first selected character
347 void replaceSelectionWithString(std::string const & str);
349 /// needed to insert the selection
350 void insertStringAsLines(std::string const & str);
351 /// needed to insert the selection
352 void insertStringAsParagraphs(std::string const & str);
354 /// Find next inset of some specified type.
355 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
356 std::string const & contents = std::string());
358 void gotoInset(std::vector<InsetOld::Code> const & codes,
361 void gotoInset(InsetOld::Code code, bool same_content);
364 int workWidth() const;
367 void computeBidiTables(ParagraphList::iterator pit,
368 Buffer const &, RowList::iterator row) const;
369 /// Maps positions in the visual string to positions in logical string.
370 lyx::pos_type log2vis(lyx::pos_type pos) const;
371 /// Maps positions in the logical string to positions in visual string.
372 lyx::pos_type vis2log(lyx::pos_type pos) const;
374 lyx::pos_type bidi_level(lyx::pos_type pos) const;
376 bool bidi_InRange(lyx::pos_type pos) const;
379 float getCursorX(ParagraphList::iterator pit,
380 RowList::iterator rit, lyx::pos_type pos,
381 lyx::pos_type last, bool boundary) const;
382 /// used in setlayout
383 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
385 /// Calculate and set the height of the row
386 void setHeightOfRow(ParagraphList::iterator, RowList::iterator rit);
388 // fix the cursor `cur' after a characters has been deleted at `where'
389 // position. Called by deleteEmptyParagraphMechanism
390 void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
392 /// delete double space (false) or empty paragraphs (true) around old_cursor
393 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
396 /** Updates all counters starting BEHIND the row. Changed paragraphs
397 * with a dynamic left margin will be rebroken. */
398 void updateCounters();
400 * Returns an inset if inset was hit, or 0 if not.
401 * If hit, the coordinates are changed relative to the inset.
403 InsetOld * checkInsetHit(int & x, int & y);
406 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
408 int singleWidth(ParagraphList::iterator pit,
409 lyx::pos_type pos, char c, LyXFont const & Font) const;
411 /// return the color of the canvas
412 LColor_color backgroundColor() const;
415 mutable bool bidi_same_direction;
417 unsigned char transformChar(unsigned char c, Paragraph const & par,
418 lyx::pos_type pos) const;
421 * Returns the left beginning of the text.
422 * This information cannot be taken from the layout object, because
423 * in LaTeX the beginning of the text fits in some cases
424 * (for example sections) exactly the label-width.
426 int leftMargin(ParagraphList::iterator pit, Row const & row) const;
428 int rightMargin(ParagraphList::iterator pit, Buffer const &, Row const & row) const;
430 /** this calculates the specified parameters. needed when setting
431 * the cursor and when creating a visible row */
432 void prepareToPrint(ParagraphList::iterator pit,
433 RowList::iterator row) const;
437 void setCounter(Buffer const &, ParagraphList::iterator pit);
439 void deleteWordForward();
441 void deleteWordBackward();
443 void deleteLineForward();
446 * some low level functions
450 /// sets row.end to the pos value *after* which a row should break.
451 /// for example, the pos after which isNewLine(pos) == true
452 lyx::pos_type rowBreakPoint(ParagraphList::iterator pit,
453 Row const & row) const;
455 /// returns the minimum space a row needs on the screen in pixel
456 int fill(ParagraphList::iterator pit,
457 RowList::iterator row, int workwidth) const;
460 * returns the minimum space a manual label needs on the
463 int labelFill(ParagraphList::iterator pit, Row const & row) const;
466 int labelEnd(ParagraphList::iterator pit, Row const & row) const;
469 mutable std::vector<lyx::pos_type> log2vis_list;
471 mutable std::vector<lyx::pos_type> vis2log_list;
473 mutable std::vector<lyx::pos_type> bidi_levels;
475 mutable lyx::pos_type bidi_start;
477 mutable lyx::pos_type bidi_end;
485 ParagraphList * paragraphs_;
487 // special owner functions
489 ParagraphList & ownerParagraphs() const;
491 /// return true if this is owned by an inset.
492 bool isInInset() const;
494 /// return first row of text
495 RowList::iterator firstRow() const;
496 /// return last row of text
497 RowList::iterator lastRow() const;
498 /// return row "behind" last row of text
499 RowList::iterator endRow() const;
500 /// return next row crossing paragraph boundaries
501 void nextRow(ParagraphList::iterator & pit,
502 RowList::iterator & rit) const;
503 /// return previous row crossing paragraph boundaries
504 void previousRow(ParagraphList::iterator & pit,
505 RowList::iterator & rit) const;
508 std::string selectionAsString(Buffer const & buffer, bool label) const;
510 /** Cursor related data.
511 Later this variable has to be removed. There should be now internal
514 ///TextCursor cursor_;
515 /// prohibit this as long as there are back pointers...
516 LyXText(LyXText const &);
519 /// return the default height of a row in pixels, considering font zoom
520 extern int defaultRowHeight();