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
18 #include "lyxcursor.h"
21 #include "insets/inset.h"
23 #include "bufferview_funcs.h"
24 #include "textcursor.h"
42 This class used to hold the mapping between buffer paragraphs and
43 screen rows. Nowadays, the Paragraphs take care of their rows
44 themselves and this contains just most of the code for manipulating
45 them and interaction with the Cursor.
48 // The inheritance from TextCursor should go. It's just there to ease
50 class LyXText : public TextCursor {
53 LyXText(BufferView *);
54 /// sets inset as owner
55 LyXText(BufferView *, InsetText *);
57 void init(BufferView *);
62 /// the current font settings
65 LyXFont real_current_font;
66 /// our buffer's default layout font
69 /** the 'anchor' row: the position of this row remains constant
70 * with respect to the top of the screen
72 RowList::iterator anchor_row_;
73 /** the pixel offset with respect to this row of top_y
75 int anchor_row_offset_;
77 /// update all cached row positions
78 void updateRowPositions();
79 /// get the y coord. of the top of the screen (relative to doc start)
81 /// set the y coord. of the top of the screen (relative to doc start)
83 /// set the anchoring row. top_y will be computed relative to this
84 void anchor_row(RowList::iterator rit);
86 InsetText * inset_owner;
88 UpdatableInset * the_locking_inset;
91 int getRealCursorX() const;
93 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
95 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
97 LyXFont getLabelFont(ParagraphList::iterator pit) const;
99 void setCharFont(ParagraphList::iterator pit,
100 lyx::pos_type pos, LyXFont const & font);
101 void setCharFont(ParagraphList::iterator pit,
103 LyXFont const & font, bool toggleall);
105 /// what you expect when pressing <enter> at cursor position
106 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
108 /** set layout over selection and make a total rebreak of
111 ParagraphList::iterator
112 setLayout(LyXCursor & actual_cursor,
113 LyXCursor & selection_start,
114 LyXCursor & selection_end,
115 string const & layout);
117 void setLayout(string const & layout);
120 * Increase or decrease the nesting depth of the selected paragraph(s)
121 * if test_only, don't change any depths. Returns whether something
122 * (would have) changed
124 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
126 /// get the depth at current cursor position
127 int getDepth() const;
129 /** set font over selection and make a total rebreak of those
131 toggleall defaults to false.
133 void setFont(LyXFont const &, bool toggleall = false);
135 /// rebreaks all paragaphs between the given pars.
136 void redoParagraphs(ParagraphList::iterator begin,
137 ParagraphList::iterator end);
138 /// rebreaks the given par
139 void redoParagraph(ParagraphList::iterator pit);
140 /// rebreaks the cursor par
141 void redoParagraph();
144 void toggleFree(LyXFont const &, bool toggleall = false);
147 string getStringToIndex();
149 /** insert a character, moves all the following breaks in the
150 same Paragraph one to the right and make a little rebreak
152 void insertChar(char c);
154 void insertInset(InsetOld * inset);
156 /// a full rebreak of the whole text
158 /// compute text metrics
159 void metrics(MetricsInfo & mi, Dimension & dim);
162 InsetOld::RESULT dispatch(FuncRequest const & cmd);
166 BufferView * bv() const;
168 friend class LyXScreen;
171 /// only the top-level LyXText has this non-zero
172 BufferView * bv_owner;
175 /// returns a pointer to a specified row.
177 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
179 /// returns a pointer cursor row
180 RowList::iterator getRow(LyXCursor const & cursor) const;
182 RowList::iterator cursorRow() const;
184 * Return the next row, when cursor is at the end of the
185 * previous row, for insets that take a full row.
187 * FIXME: explain why we need this ? especially for y...
189 RowList::iterator cursorIRow() const;
191 /** returns a pointer to the row near the specified y-coordinate
192 (relative to the whole text). y is set to the real beginning
195 RowList::iterator getRowNearY(int & y,
196 ParagraphList::iterator & pit) const;
198 /** returns the column near the specified x-coordinate of the row
199 x is set to the real beginning of this column
201 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
202 RowList::iterator rit, int & x, bool & boundary) const;
204 /** returns a pointer to a specified row. y is set to the beginning
208 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
210 /// need the selection cursor:
213 void clearSelection();
215 /// select the word we need depending on word_location
216 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
217 /// just selects the word the cursor is in
218 void selectWord(lyx::word_location loc);
219 /// returns the inset at cursor (if it exists), 0 otherwise
220 InsetOld * getInset() const;
222 /// accept selected change
225 /// reject selected change
228 /** 'selects" the next word, where the cursor is not in
229 and returns this word as string. THe cursor will be moved
230 to the beginning of this word.
231 With SelectSelectedWord can this be highlighted really
233 WordLangTuple const selectNextWordToSpellcheck(float & value);
235 void selectSelectedWord();
236 /// re-computes the cached coordinates in the cursor
238 /// returns true if par was empty and was removed
239 bool setCursor(ParagraphList::iterator pit,
242 bool boundary = false);
244 void setCursor(LyXCursor &, ParagraphList::iterator pit,
246 bool boundary = false);
248 void setCursorIntern(ParagraphList::iterator pit,
251 bool boundary = false);
253 void setCurrentFont();
256 bool isBoundary(Buffer const *, Paragraph const & par,
257 lyx::pos_type pos) const;
259 bool isBoundary(Buffer const *, Paragraph const & par,
261 LyXFont const & font) const;
264 void setCursorFromCoordinates(int x, int y);
266 void setCursorFromCoordinates(LyXCursor &,
269 void cursorUp(bool selecting = false);
271 void cursorDown(bool selecting = false);
273 void cursorLeft(bool internal = true);
275 void cursorRight(bool internal = true);
277 void cursorLeftOneWord();
279 void cursorRightOneWord();
281 void cursorUpParagraph();
283 void cursorDownParagraph();
289 void cursorPrevious();
301 bool selectWordWhenUnderCursor(lyx::word_location);
307 text_capitalization = 1,
311 /// Change the case of the word at cursor position.
312 void changeCase(TextCase action);
317 void cutSelection(bool doclear = true, bool realcut = true);
319 void copySelection();
321 void pasteSelection(size_t sel_index = 0);
323 /** the DTP switches for paragraphs. LyX will store the top settings
324 always in the first physical paragraph, the bottom settings in the
325 last. When a paragraph is broken, the top settings rest, the bottom
326 settings are given to the new one. So I can make shure, they do not
327 duplicate themself (and you cannnot make dirty things with them! )
329 void setParagraph(bool line_top, bool line_bottom,
330 bool pagebreak_top, bool pagebreak_bottom,
331 VSpace const & space_top,
332 VSpace const & space_bottom,
333 Spacing const & spacing,
335 string const & labelwidthstring,
338 /* these things are for search and replace */
341 * Sets the selection from the current cursor position to length
342 * characters to the right. No safety checks.
344 void setSelectionRange(lyx::pos_type length);
346 /** simple replacing. The font of the first selected character
349 void replaceSelectionWithString(string const & str);
351 /// needed to insert the selection
352 void insertStringAsLines(string const & str);
353 /// needed to insert the selection
354 void insertStringAsParagraphs(string const & str);
356 /// Find next inset of some specified type.
357 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
358 string const & contents = string());
360 void gotoInset(std::vector<InsetOld::Code> const & codes,
363 void gotoInset(InsetOld::Code code, bool same_content);
366 int workWidth() const;
369 void computeBidiTables(ParagraphList::iterator pit,
370 Buffer const *, RowList::iterator row) const;
371 /// Maps positions in the visual string to positions in logical string.
372 lyx::pos_type log2vis(lyx::pos_type pos) const;
373 /// Maps positions in the logical string to positions in visual string.
374 lyx::pos_type vis2log(lyx::pos_type pos) const;
376 lyx::pos_type bidi_level(lyx::pos_type pos) const;
378 bool bidi_InRange(lyx::pos_type pos) const;
381 float getCursorX(ParagraphList::iterator pit,
382 RowList::iterator rit, lyx::pos_type pos,
383 lyx::pos_type last, bool boundary) const;
384 /// used in setlayout
385 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
387 /// Calculate and set the height of the row
388 void setHeightOfRow(ParagraphList::iterator, RowList::iterator rit);
390 // fix the cursor `cur' after a characters has been deleted at `where'
391 // position. Called by deleteEmptyParagraphMechanism
392 void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
394 /// delete double space (false) or empty paragraphs (true) around old_cursor
395 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
398 /** Updates all counters starting BEHIND the row. Changed paragraphs
399 * with a dynamic left margin will be rebroken. */
400 void updateCounters();
402 * Returns an inset if inset was hit, or 0 if not.
403 * If hit, the coordinates are changed relative to the inset.
405 InsetOld * checkInsetHit(int & x, int & y);
408 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
410 int singleWidth(ParagraphList::iterator pit,
411 lyx::pos_type pos, char c) const;
412 /// rebuild row cache
413 void rebuildRows(ParagraphList::iterator pit);
415 /// return the color of the canvas
416 LColor::color backgroundColor() const;
419 mutable bool bidi_same_direction;
421 unsigned char transformChar(unsigned char c, Paragraph const & par,
422 lyx::pos_type pos) const;
425 * Returns the left beginning of the text.
426 * This information cannot be taken from the layout object, because
427 * in LaTeX the beginning of the text fits in some cases
428 * (for example sections) exactly the label-width.
430 int leftMargin(ParagraphList::iterator pit, Row const & row) const;
432 int rightMargin(ParagraphList::iterator pit, Buffer const &, Row const & row) const;
434 /** this calculates the specified parameters. needed when setting
435 * the cursor and when creating a visible row */
437 ParagraphList::iterator pit,
438 RowList::iterator row, double & x,
439 double & fill_separator,
441 double & fill_label_hfill,
442 bool bidi = true) const;
446 void setCounter(Buffer const *, ParagraphList::iterator pit);
448 void deleteWordForward();
450 void deleteWordBackward();
452 void deleteLineForward();
455 * some low level functions
459 /// return the pos value *before* which a row should break.
460 /// for example, the pos at which IsNewLine(pos) == true
461 lyx::pos_type rowBreakPoint(ParagraphList::iterator pit,
462 Row const & row) const;
464 /// returns the minimum space a row needs on the screen in pixel
465 int fill(ParagraphList::iterator pit,
466 RowList::iterator row, int workwidth) const;
469 * returns the minimum space a manual label needs on the
472 int labelFill(ParagraphList::iterator pit, Row const & row) const;
475 int labelEnd(ParagraphList::iterator pit, Row const & row) const;
478 mutable std::vector<lyx::pos_type> log2vis_list;
480 mutable std::vector<lyx::pos_type> vis2log_list;
482 mutable std::vector<lyx::pos_type> bidi_levels;
484 mutable lyx::pos_type bidi_start;
486 mutable lyx::pos_type bidi_end;
492 // special owner functions
494 ParagraphList & ownerParagraphs() const;
496 /// return true if this is owned by an inset.
497 bool isInInset() const;
499 /// return first row of text
500 RowList::iterator firstRow() const;
501 /// return last row of text
502 RowList::iterator lastRow() const;
503 /// return row "behind" last row of text
504 RowList::iterator endRow() const;
505 /// return next row crossing paragraph boundaries
506 void nextRow(ParagraphList::iterator & pit,
507 RowList::iterator & rit) const;
508 /// return previous row crossing paragraph boundaries
509 void previousRow(ParagraphList::iterator & pit,
510 RowList::iterator & rit) const;
516 /** Cursor related data.
517 Later this variable has to be removed. There should be now internal
520 ///TextCursor cursor_;
523 /// return the default height of a row in pixels, considering font zoom
524 extern int defaultRowHeight();