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"
40 This class holds the mapping between buffer paragraphs and screen rows.
43 // The inheritance from TextCursor should go. It's just there to ease
45 class LyXText : public TextCursor {
47 /// what repainting is needed
49 /// no repaint is needed
51 /// the refresh_row needs repainting
53 /// everything from refresh_y downwards needs repainting
58 LyXText(BufferView *);
59 /// sets inset as owner
60 LyXText(BufferView *, InsetText *);
62 void init(BufferView *, bool reinit = false);
67 /// the current font settings
70 LyXFont real_current_font;
72 /** the 'anchor' row: the position of this row remains constant
73 * with respect to the top of the screen
75 RowList::iterator anchor_row_;
76 /** the pixel offset with respect to this row of top_y
78 int anchor_row_offset_;
80 /// update all cached row positions
81 void updateRowPositions();
82 /// get the y coord. of the top of the screen (relative to doc start)
84 /// set the y coord. of the top of the screen (relative to doc start)
86 /// set the anchoring row. top_y will be computed relative to this
87 void anchor_row(RowList::iterator rit);
89 InsetText * inset_owner;
91 UpdatableInset * the_locking_inset;
94 int getRealCursorX() const;
96 LyXFont const getFont(Buffer const *, ParagraphList::iterator pit,
97 lyx::pos_type pos) const;
99 LyXFont const getLayoutFont(Buffer const *,
100 ParagraphList::iterator pit) const;
102 LyXFont const getLabelFont(Buffer const *,
103 ParagraphList::iterator pit) const;
105 void setCharFont(Buffer const *, ParagraphList::iterator pit,
106 lyx::pos_type pos, LyXFont const & font);
107 void setCharFont(ParagraphList::iterator pit,
109 LyXFont const & font, bool toggleall);
112 void breakAgainOneRow(RowList::iterator rit);
113 /// what you expect when pressing <enter> at cursor position
114 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
116 /** set layout over selection and make a total rebreak of
119 ParagraphList::iterator
120 setLayout(LyXCursor & actual_cursor,
121 LyXCursor & selection_start,
122 LyXCursor & selection_end,
123 string const & layout);
125 void setLayout(string const & layout);
128 * Increase or decrease the nesting depth of the selected paragraph(s)
129 * if test_only, don't change any depths. Returns whether something
130 * (would have) changed
132 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
134 /// get the depth at current cursor position
135 int getDepth() const;
137 /** set font over selection and make a total rebreak of those
139 toggleall defaults to false.
141 void setFont(LyXFont const &, bool toggleall = false);
143 /** deletes and inserts again all paragaphs between the cursor
144 and the specified par. The Cursor is needed to set the refreshing
146 This function is needed after SetLayout and SetFont etc.
148 void redoParagraphs(LyXCursor const & cursor,
149 ParagraphList::iterator endpit);
151 void redoParagraph();
154 void toggleFree(LyXFont const &, bool toggleall = false);
157 string getStringToIndex();
159 /** recalculates the heights of all previous rows of the
160 specified paragraph. needed, if the last characters font
163 void redoHeightOfParagraph();
165 /** insert a character, moves all the following breaks in the
166 same Paragraph one to the right and make a little rebreak
168 void insertChar(char c);
170 void insertInset(Inset * inset);
172 /// Completes the insertion with a rebreak from 'need_break_row' on
173 void partialRebreak();
174 /// a full rebreak of the whole text
178 RowList::iterator need_break_row;
180 /// clear any pending paints
184 * Mark position y as the starting point for a repaint
186 void postPaint(int start_y);
189 * Mark the given row at position y as needing a repaint.
191 void postRowPaint(RowList::iterator rit, int start_y);
194 Inset::RESULT dispatch(FuncRequest const & cmd);
198 BufferView * bv() const;
200 friend class LyXScreen;
203 * Return the status. This represents what repaints are
204 * pending after some operation (e.g. inserting a char).
206 refresh_status refreshStatus() const;
210 * The pixel y position from which to repaint the screen.
211 * The position is absolute along the height of outermost
212 * lyxtext (I think). REFRESH_AREA and REFRESH_ROW
213 * repaints both use this as a starting point (if it's within
214 * the viewable portion of the lyxtext).
218 * The row from which to repaint the screen, used by screen.c.
219 * This must be set if the pending update is REFRESH_ROW.
220 * It doesn't make any difference for REFRESH_AREA.
222 RowList::iterator refresh_row;
224 refresh_status refresh_status_;
227 /// only the top-level LyXText has this non-zero
228 BufferView * bv_owner;
231 /// returns a pointer to a specified row.
233 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
235 /// returns a pointer cursor row
236 RowList::iterator getRow(LyXCursor const & cursor) const;
238 RowList::iterator cursorRow() const;
240 /** returns a pointer to the row near the specified y-coordinate
241 (relative to the whole text). y is set to the real beginning
244 RowList::iterator getRowNearY(int & y) const;
246 /** returns the column near the specified x-coordinate of the row
247 x is set to the real beginning of this column
249 lyx::pos_type getColumnNearX(RowList::iterator rit,
250 int & x, bool & boundary) const;
252 /** returns a pointer to a specified row. y is set to the beginning
256 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
258 RowList & rows() const {
263 /// need the selection cursor:
266 void clearSelection();
268 /// select the word we need depending on word_location
269 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
270 /// just selects the word the cursor is in
271 void selectWord(lyx::word_location loc);
272 /// returns the inset at cursor (if it exists), 0 otherwise
273 Inset * getInset() const;
275 /// accept selected change
278 /// reject selected change
281 /** 'selects" the next word, where the cursor is not in
282 and returns this word as string. THe cursor will be moved
283 to the beginning of this word.
284 With SelectSelectedWord can this be highlighted really
286 WordLangTuple const selectNextWordToSpellcheck(float & value);
288 void selectSelectedWord();
289 /// returns true if par was empty and was removed
290 bool setCursor(ParagraphList::iterator pit,
293 bool boundary = false);
295 void setCursor(LyXCursor &, ParagraphList::iterator pit,
297 bool boundary = false);
299 void setCursorIntern(ParagraphList::iterator pit,
302 bool boundary = false);
304 void setCurrentFont();
307 bool isBoundary(Buffer const *, Paragraph const & par,
308 lyx::pos_type pos) const;
310 bool isBoundary(Buffer const *, Paragraph const & par,
312 LyXFont const & font) const;
315 void setCursorFromCoordinates(int x, int y);
317 void setCursorFromCoordinates(LyXCursor &,
320 void cursorUp(bool selecting = false);
322 void cursorDown(bool selecting = false);
324 void cursorLeft(bool internal = true);
326 void cursorRight(bool internal = true);
328 void cursorLeftOneWord();
330 void cursorRightOneWord();
332 void cursorUpParagraph();
334 void cursorDownParagraph();
340 void cursorPrevious();
352 bool selectWordWhenUnderCursor(lyx::word_location);
358 text_capitalization = 1,
362 /// Change the case of the word at cursor position.
363 void changeCase(TextCase action);
368 void cutSelection(bool doclear = true, bool realcut = true);
370 void copySelection();
372 void pasteSelection(size_t sel_index = 0);
374 /** the DTP switches for paragraphs. LyX will store the top settings
375 always in the first physical paragraph, the bottom settings in the
376 last. When a paragraph is broken, the top settings rest, the bottom
377 settings are given to the new one. So I can make shure, they do not
378 duplicate themself (and you cannnot make dirty things with them! )
380 void setParagraph(bool line_top, bool line_bottom,
381 bool pagebreak_top, bool pagebreak_bottom,
382 VSpace const & space_top,
383 VSpace const & space_bottom,
384 Spacing const & spacing,
386 string const & labelwidthstring,
389 /* these things are for search and replace */
392 * Sets the selection from the current cursor position to length
393 * characters to the right. No safety checks.
395 void setSelectionRange(lyx::pos_type length);
397 /** simple replacing. The font of the first selected character
400 void replaceSelectionWithString(string const & str);
402 /// needed to insert the selection
403 void insertStringAsLines(string const & str);
404 /// needed to insert the selection
405 void insertStringAsParagraphs(string const & str);
407 /// Find next inset of some specified type.
408 bool gotoNextInset(std::vector<Inset::Code> const & codes,
409 string const & contents = string());
411 void gotoInset(std::vector<Inset::Code> const & codes,
414 void gotoInset(Inset::Code code, bool same_content);
417 /* for the greater insets */
419 /// returns false if inset wasn't found
420 bool updateInset(Inset *);
422 void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos);
424 int workWidth() const;
425 /// returns width of row containing inset
426 int workWidth(Inset const * inset) const;
429 void computeBidiTables(Buffer const *, RowList::iterator row) const;
430 /// Maps positions in the visual string to positions in logical string.
431 lyx::pos_type log2vis(lyx::pos_type pos) const;
432 /// Maps positions in the logical string to positions in visual string.
433 lyx::pos_type vis2log(lyx::pos_type pos) const;
435 lyx::pos_type bidi_level(lyx::pos_type pos) const;
437 bool bidi_InRange(lyx::pos_type pos) const;
440 mutable RowList rowlist_;
443 float getCursorX(RowList::iterator rit, lyx::pos_type pos,
444 lyx::pos_type last, bool boundary) const;
445 /// used in setlayout
446 void makeFontEntriesLayoutSpecific(Buffer const &, Paragraph & par);
448 /** forces the redrawing of a paragraph. Needed when manipulating a
451 void redoDrawingOfParagraph(LyXCursor const & cursor);
453 /// removes the row and reset the touched counters
454 void removeRow(RowList::iterator rit);
456 /// remove all following rows of the paragraph of the specified row.
457 void removeParagraph(RowList::iterator rit);
459 /// insert the specified paragraph behind the specified row
460 void insertParagraph(ParagraphList::iterator pit,
461 RowList::iterator rowit);
463 /** appends the implizit specified paragraph behind the specified row,
464 * start at the implizit given position */
465 void appendParagraph(RowList::iterator rowit);
468 void breakAgain(RowList::iterator rit);
469 /// Calculate and set the height of the row
470 void setHeightOfRow(RowList::iterator rit);
472 // fix the cursor `cur' after a characters has been deleted at `where'
473 // position. Called by deleteEmptyParagraphMechanism
474 void fixCursorAfterDelete(LyXCursor & cur,
475 LyXCursor const & where);
477 /// delete double space (false) or empty paragraphs (true) around old_cursor
478 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
481 /** Updates all counters starting BEHIND the row. Changed paragraphs
482 * with a dynamic left margin will be rebroken. */
483 void updateCounters();
487 * Returns an inset if inset was hit, or 0 if not.
488 * If hit, the coordinates are changed relative to the inset.
490 Inset * checkInsetHit(int & x, int & y);
493 int singleWidth(ParagraphList::iterator pit,
494 lyx::pos_type pos) const;
496 int singleWidth(ParagraphList::iterator pit,
497 lyx::pos_type pos, char c) const;
499 /// return the color of the canvas
500 LColor::color backgroundColor() const;
503 mutable bool bidi_same_direction;
505 unsigned char transformChar(unsigned char c, Paragraph const & par,
506 lyx::pos_type pos) const;
509 * Returns the left beginning of the text.
510 * This information cannot be taken from the layout object, because
511 * in LaTeX the beginning of the text fits in some cases
512 * (for example sections) exactly the label-width.
514 int leftMargin(Row const & row) const;
516 int rightMargin(Buffer const &, Row const & row) const;
518 /** this calculates the specified parameters. needed when setting
519 * the cursor and when creating a visible row */
520 void prepareToPrint(RowList::iterator row, float & x,
521 float & fill_separator,
523 float & fill_label_hfill,
524 bool bidi = true) const;
528 void setCounter(Buffer const *, ParagraphList::iterator pit);
530 void deleteWordForward();
532 void deleteWordBackward();
534 void deleteLineForward();
537 * some low level functions
541 /// return the pos value *before* which a row should break.
542 /// for example, the pos at which IsNewLine(pos) == true
543 lyx::pos_type rowBreakPoint(Row const & row) const;
545 /// returns the minimum space a row needs on the screen in pixel
546 int fill(RowList::iterator row, int workwidth) const;
549 * returns the minimum space a manual label needs on the
552 int labelFill(Row const & row) const;
555 int labelEnd(Row const & row) const;
558 mutable std::vector<lyx::pos_type> log2vis_list;
560 mutable std::vector<lyx::pos_type> vis2log_list;
562 mutable std::vector<lyx::pos_type> bidi_levels;
564 mutable lyx::pos_type bidi_start;
566 mutable lyx::pos_type bidi_end;
572 // special owner functions
574 ParagraphList & ownerParagraphs() const;
576 /// return true if this is owned by an inset.
577 bool isInInset() const;
580 /** Cursor related data.
581 Later this variable has to be removed. There should be now internal
584 ///TextCursor cursor_;
587 /// return the default height of a row in pixels, considering font zoom
588 extern int defaultRowHeight();