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 holds the mapping between buffer paragraphs and screen rows.
45 // The inheritance from TextCursor should go. It's just there to ease
47 class LyXText : public TextCursor {
50 LyXText(BufferView *);
51 /// sets inset as owner
52 LyXText(BufferView *, InsetText *);
54 void init(BufferView *);
59 /// the current font settings
62 LyXFont real_current_font;
64 /** the 'anchor' row: the position of this row remains constant
65 * with respect to the top of the screen
67 RowList::iterator anchor_row_;
68 /** the pixel offset with respect to this row of top_y
70 int anchor_row_offset_;
72 /// update all cached row positions
73 void updateRowPositions();
74 /// get the y coord. of the top of the screen (relative to doc start)
76 /// set the y coord. of the top of the screen (relative to doc start)
78 /// set the anchoring row. top_y will be computed relative to this
79 void anchor_row(RowList::iterator rit);
81 InsetText * inset_owner;
83 UpdatableInset * the_locking_inset;
86 int getRealCursorX() const;
88 LyXFont const getFont(Buffer const *, ParagraphList::iterator pit,
89 lyx::pos_type pos) const;
91 LyXFont const getLayoutFont(Buffer const *,
92 ParagraphList::iterator pit) const;
94 LyXFont const getLabelFont(Buffer const *,
95 ParagraphList::iterator pit) const;
97 void setCharFont(Buffer const *, ParagraphList::iterator pit,
98 lyx::pos_type pos, LyXFont const & font);
99 void setCharFont(ParagraphList::iterator pit,
101 LyXFont const & font, bool toggleall);
104 void breakAgainOneRow(RowList::iterator rit);
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 /** deletes and inserts again all paragaphs between the cursor
136 and the specified par. The Cursor is needed to set the refreshing
138 This function is needed after SetLayout and SetFont etc.
140 void redoParagraphs(LyXCursor const & cursor,
141 ParagraphList::iterator endpit);
143 void redoParagraph();
146 void toggleFree(LyXFont const &, bool toggleall = false);
149 string getStringToIndex();
151 /** recalculates the heights of all previous rows of the
152 specified paragraph. needed, if the last characters font
155 void redoHeightOfParagraph();
157 /** insert a character, moves all the following breaks in the
158 same Paragraph one to the right and make a little rebreak
160 void insertChar(char c);
162 void insertInset(Inset * inset);
164 /// Completes the insertion with a rebreak from 'need_break_row' on
165 void partialRebreak();
166 /// a full rebreak of the whole text
168 /// compute text metrics
169 void metrics(MetricsInfo & mi, Dimension & dim);
172 RowList::iterator need_break_row;
174 /// clear any pending paints
177 /// submit repaint request
181 Inset::RESULT dispatch(FuncRequest const & cmd);
185 BufferView * bv() const;
187 friend class LyXScreen;
190 * Return the status. This represents what repaints are
191 * pending after some operation (e.g. inserting a char).
193 bool needRefresh() const;
196 // do we need a refresh?
200 /// only the top-level LyXText has this non-zero
201 BufferView * bv_owner;
204 /// returns a pointer to a specified row.
206 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
208 /// returns a pointer cursor row
209 RowList::iterator getRow(LyXCursor const & cursor) const;
211 RowList::iterator cursorRow() const;
213 * Return the next row, when cursor is at the end of the
214 * previous row, for insets that take a full row.
216 * FIXME: explain why we need this ? especially for y...
218 RowList::iterator cursorIRow() const;
220 /** returns a pointer to the row near the specified y-coordinate
221 (relative to the whole text). y is set to the real beginning
224 RowList::iterator getRowNearY(int & y) const;
226 /** returns the column near the specified x-coordinate of the row
227 x is set to the real beginning of this column
229 lyx::pos_type getColumnNearX(RowList::iterator rit,
230 int & x, bool & boundary) const;
232 /** returns a pointer to a specified row. y is set to the beginning
236 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
238 RowList & rows() const {
243 /// need the selection cursor:
246 void clearSelection();
248 /// select the word we need depending on word_location
249 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
250 /// just selects the word the cursor is in
251 void selectWord(lyx::word_location loc);
252 /// returns the inset at cursor (if it exists), 0 otherwise
253 Inset * getInset() const;
255 /// accept selected change
258 /// reject selected change
261 /** 'selects" the next word, where the cursor is not in
262 and returns this word as string. THe cursor will be moved
263 to the beginning of this word.
264 With SelectSelectedWord can this be highlighted really
266 WordLangTuple const selectNextWordToSpellcheck(float & value);
268 void selectSelectedWord();
269 /// returns true if par was empty and was removed
270 bool setCursor(ParagraphList::iterator pit,
273 bool boundary = false);
275 void setCursor(LyXCursor &, ParagraphList::iterator pit,
277 bool boundary = false);
279 void setCursorIntern(ParagraphList::iterator pit,
282 bool boundary = false);
284 void setCurrentFont();
287 bool isBoundary(Buffer const *, Paragraph const & par,
288 lyx::pos_type pos) const;
290 bool isBoundary(Buffer const *, Paragraph const & par,
292 LyXFont const & font) const;
295 void setCursorFromCoordinates(int x, int y);
297 void setCursorFromCoordinates(LyXCursor &,
300 void cursorUp(bool selecting = false);
302 void cursorDown(bool selecting = false);
304 void cursorLeft(bool internal = true);
306 void cursorRight(bool internal = true);
308 void cursorLeftOneWord();
310 void cursorRightOneWord();
312 void cursorUpParagraph();
314 void cursorDownParagraph();
320 void cursorPrevious();
332 bool selectWordWhenUnderCursor(lyx::word_location);
338 text_capitalization = 1,
342 /// Change the case of the word at cursor position.
343 void changeCase(TextCase action);
348 void cutSelection(bool doclear = true, bool realcut = true);
350 void copySelection();
352 void pasteSelection(size_t sel_index = 0);
354 /** the DTP switches for paragraphs. LyX will store the top settings
355 always in the first physical paragraph, the bottom settings in the
356 last. When a paragraph is broken, the top settings rest, the bottom
357 settings are given to the new one. So I can make shure, they do not
358 duplicate themself (and you cannnot make dirty things with them! )
360 void setParagraph(bool line_top, bool line_bottom,
361 bool pagebreak_top, bool pagebreak_bottom,
362 VSpace const & space_top,
363 VSpace const & space_bottom,
364 Spacing const & spacing,
366 string const & labelwidthstring,
369 /* these things are for search and replace */
372 * Sets the selection from the current cursor position to length
373 * characters to the right. No safety checks.
375 void setSelectionRange(lyx::pos_type length);
377 /** simple replacing. The font of the first selected character
380 void replaceSelectionWithString(string const & str);
382 /// needed to insert the selection
383 void insertStringAsLines(string const & str);
384 /// needed to insert the selection
385 void insertStringAsParagraphs(string const & str);
387 /// Find next inset of some specified type.
388 bool gotoNextInset(std::vector<Inset::Code> const & codes,
389 string const & contents = string());
391 void gotoInset(std::vector<Inset::Code> const & codes,
394 void gotoInset(Inset::Code code, bool same_content);
397 /* for the greater insets */
399 /// returns false if inset wasn't found
400 bool updateInset(Inset *);
402 void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos);
404 int workWidth() const;
405 /// returns width of row containing inset
406 int workWidth(Inset const * inset) const;
409 void computeBidiTables(Buffer const *, RowList::iterator row) const;
410 /// Maps positions in the visual string to positions in logical string.
411 lyx::pos_type log2vis(lyx::pos_type pos) const;
412 /// Maps positions in the logical string to positions in visual string.
413 lyx::pos_type vis2log(lyx::pos_type pos) const;
415 lyx::pos_type bidi_level(lyx::pos_type pos) const;
417 bool bidi_InRange(lyx::pos_type pos) const;
420 mutable RowList rowlist_;
423 float getCursorX(RowList::iterator rit, lyx::pos_type pos,
424 lyx::pos_type last, bool boundary) const;
425 /// used in setlayout
426 void makeFontEntriesLayoutSpecific(Buffer const &, Paragraph & par);
428 /** forces the redrawing of a paragraph. Needed when manipulating a
431 void redoDrawingOfParagraph(LyXCursor const & cursor);
433 /// removes the row and reset the touched counters
434 void removeRow(RowList::iterator rit);
436 /// remove all following rows of the paragraph of the specified row.
437 void removeParagraph(RowList::iterator rit);
439 /// insert the specified paragraph behind the specified row
440 void insertParagraph(ParagraphList::iterator pit,
441 RowList::iterator rowit);
443 /** appends the implizit specified paragraph behind the specified row,
444 * start at the implizit given position */
445 void appendParagraph(RowList::iterator rowit);
448 void breakAgain(RowList::iterator rit);
449 /// Calculate and set the height of the row
450 void setHeightOfRow(RowList::iterator rit);
452 // fix the cursor `cur' after a characters has been deleted at `where'
453 // position. Called by deleteEmptyParagraphMechanism
454 void fixCursorAfterDelete(LyXCursor & cur,
455 LyXCursor const & where);
457 /// delete double space (false) or empty paragraphs (true) around old_cursor
458 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
461 /** Updates all counters starting BEHIND the row. Changed paragraphs
462 * with a dynamic left margin will be rebroken. */
463 void updateCounters();
467 * Returns an inset if inset was hit, or 0 if not.
468 * If hit, the coordinates are changed relative to the inset.
470 Inset * checkInsetHit(int & x, int & y);
473 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
475 int singleWidth(ParagraphList::iterator pit,
476 lyx::pos_type pos, char c) const;
477 /// rebuild row cache
478 void rebuildRows(ParagraphList::iterator pit);
480 /// return the color of the canvas
481 LColor::color backgroundColor() const;
484 mutable bool bidi_same_direction;
486 unsigned char transformChar(unsigned char c, Paragraph const & par,
487 lyx::pos_type pos) const;
490 * Returns the left beginning of the text.
491 * This information cannot be taken from the layout object, because
492 * in LaTeX the beginning of the text fits in some cases
493 * (for example sections) exactly the label-width.
495 int leftMargin(Row const & row) const;
497 int rightMargin(Buffer const &, Row const & row) const;
499 /** this calculates the specified parameters. needed when setting
500 * the cursor and when creating a visible row */
501 void prepareToPrint(RowList::iterator row, int & x,
502 int & fill_separator,
504 int & fill_label_hfill,
505 bool bidi = true) const;
509 void setCounter(Buffer const *, ParagraphList::iterator pit);
511 void deleteWordForward();
513 void deleteWordBackward();
515 void deleteLineForward();
518 * some low level functions
522 /// return the pos value *before* which a row should break.
523 /// for example, the pos at which IsNewLine(pos) == true
524 lyx::pos_type rowBreakPoint(Row const & row) const;
526 /// returns the minimum space a row needs on the screen in pixel
527 int fill(RowList::iterator row, int workwidth) const;
530 * returns the minimum space a manual label needs on the
533 int labelFill(Row const & row) const;
536 int labelEnd(Row const & row) const;
539 mutable std::vector<lyx::pos_type> log2vis_list;
541 mutable std::vector<lyx::pos_type> vis2log_list;
543 mutable std::vector<lyx::pos_type> bidi_levels;
545 mutable lyx::pos_type bidi_start;
547 mutable lyx::pos_type bidi_end;
553 // special owner functions
555 ParagraphList & ownerParagraphs() const;
557 /// return true if this is owned by an inset.
558 bool isInInset() const;
561 /** Cursor related data.
562 Later this variable has to be removed. There should be now internal
565 ///TextCursor cursor_;
568 /// return the default height of a row in pixels, considering font zoom
569 extern int defaultRowHeight();