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(InsetOld * inset);
164 /// Completes the insertion with a rebreak
165 void partialRebreak();
166 /// a full rebreak of the whole text
168 /// compute text metrics
169 void metrics(MetricsInfo & mi, Dimension & dim);
171 /// clear any pending paints
174 /// submit repaint request
178 InsetOld::RESULT dispatch(FuncRequest const & cmd);
182 BufferView * bv() const;
184 friend class LyXScreen;
187 * Return the status. This represents what repaints are
188 * pending after some operation (e.g. inserting a char).
190 bool needRefresh() const;
193 // do we need a refresh?
197 /// only the top-level LyXText has this non-zero
198 BufferView * bv_owner;
201 /// returns a pointer to a specified row.
203 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
205 /// returns a pointer cursor row
206 RowList::iterator getRow(LyXCursor const & cursor) const;
208 RowList::iterator cursorRow() const;
210 * Return the next row, when cursor is at the end of the
211 * previous row, for insets that take a full row.
213 * FIXME: explain why we need this ? especially for y...
215 RowList::iterator cursorIRow() const;
217 /** returns a pointer to the row near the specified y-coordinate
218 (relative to the whole text). y is set to the real beginning
221 RowList::iterator getRowNearY(int & y) const;
223 /** returns the column near the specified x-coordinate of the row
224 x is set to the real beginning of this column
226 lyx::pos_type getColumnNearX(RowList::iterator rit,
227 int & x, bool & boundary) const;
229 /** returns a pointer to a specified row. y is set to the beginning
233 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
235 RowList & rows() const {
240 /// need the selection cursor:
243 void clearSelection();
245 /// select the word we need depending on word_location
246 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
247 /// just selects the word the cursor is in
248 void selectWord(lyx::word_location loc);
249 /// returns the inset at cursor (if it exists), 0 otherwise
250 InsetOld * getInset() const;
252 /// accept selected change
255 /// reject selected change
258 /** 'selects" the next word, where the cursor is not in
259 and returns this word as string. THe cursor will be moved
260 to the beginning of this word.
261 With SelectSelectedWord can this be highlighted really
263 WordLangTuple const selectNextWordToSpellcheck(float & value);
265 void selectSelectedWord();
266 /// returns true if par was empty and was removed
267 bool setCursor(ParagraphList::iterator pit,
270 bool boundary = false);
272 void setCursor(LyXCursor &, ParagraphList::iterator pit,
274 bool boundary = false);
276 void setCursorIntern(ParagraphList::iterator pit,
279 bool boundary = false);
281 void setCurrentFont();
284 bool isBoundary(Buffer const *, Paragraph const & par,
285 lyx::pos_type pos) const;
287 bool isBoundary(Buffer const *, Paragraph const & par,
289 LyXFont const & font) const;
292 void setCursorFromCoordinates(int x, int y);
294 void setCursorFromCoordinates(LyXCursor &,
297 void cursorUp(bool selecting = false);
299 void cursorDown(bool selecting = false);
301 void cursorLeft(bool internal = true);
303 void cursorRight(bool internal = true);
305 void cursorLeftOneWord();
307 void cursorRightOneWord();
309 void cursorUpParagraph();
311 void cursorDownParagraph();
317 void cursorPrevious();
329 bool selectWordWhenUnderCursor(lyx::word_location);
335 text_capitalization = 1,
339 /// Change the case of the word at cursor position.
340 void changeCase(TextCase action);
345 void cutSelection(bool doclear = true, bool realcut = true);
347 void copySelection();
349 void pasteSelection(size_t sel_index = 0);
351 /** the DTP switches for paragraphs. LyX will store the top settings
352 always in the first physical paragraph, the bottom settings in the
353 last. When a paragraph is broken, the top settings rest, the bottom
354 settings are given to the new one. So I can make shure, they do not
355 duplicate themself (and you cannnot make dirty things with them! )
357 void setParagraph(bool line_top, bool line_bottom,
358 bool pagebreak_top, bool pagebreak_bottom,
359 VSpace const & space_top,
360 VSpace const & space_bottom,
361 Spacing const & spacing,
363 string const & labelwidthstring,
366 /* these things are for search and replace */
369 * Sets the selection from the current cursor position to length
370 * characters to the right. No safety checks.
372 void setSelectionRange(lyx::pos_type length);
374 /** simple replacing. The font of the first selected character
377 void replaceSelectionWithString(string const & str);
379 /// needed to insert the selection
380 void insertStringAsLines(string const & str);
381 /// needed to insert the selection
382 void insertStringAsParagraphs(string const & str);
384 /// Find next inset of some specified type.
385 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
386 string const & contents = string());
388 void gotoInset(std::vector<InsetOld::Code> const & codes,
391 void gotoInset(InsetOld::Code code, bool same_content);
394 /* for the greater insets */
396 /// returns false if inset wasn't found
397 bool updateInset(InsetOld *);
399 void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos);
401 int workWidth() const;
402 /// returns width of row containing inset
403 int workWidth(InsetOld const * inset) const;
406 void computeBidiTables(Buffer const *, RowList::iterator row) const;
407 /// Maps positions in the visual string to positions in logical string.
408 lyx::pos_type log2vis(lyx::pos_type pos) const;
409 /// Maps positions in the logical string to positions in visual string.
410 lyx::pos_type vis2log(lyx::pos_type pos) const;
412 lyx::pos_type bidi_level(lyx::pos_type pos) const;
414 bool bidi_InRange(lyx::pos_type pos) const;
417 mutable RowList rowlist_;
420 float getCursorX(RowList::iterator rit, lyx::pos_type pos,
421 lyx::pos_type last, bool boundary) const;
422 /// used in setlayout
423 void makeFontEntriesLayoutSpecific(Buffer const &, Paragraph & par);
425 /** forces the redrawing of a paragraph. Needed when manipulating a
428 void redoDrawingOfParagraph(LyXCursor const & cursor);
430 /// removes the row and reset the touched counters
431 void removeRow(RowList::iterator rit);
433 /// remove all following rows of the paragraph of the specified row.
434 void removeParagraph(RowList::iterator rit);
436 /// insert the specified paragraph behind the specified row
437 void insertParagraph(ParagraphList::iterator pit,
438 RowList::iterator rowit);
440 /** appends the implizit specified paragraph behind the specified row,
441 * start at the implizit given position */
442 void appendParagraph(RowList::iterator rowit);
445 void breakAgain(RowList::iterator rit);
446 /// Calculate and set the height of the row
447 void setHeightOfRow(RowList::iterator rit);
449 // fix the cursor `cur' after a characters has been deleted at `where'
450 // position. Called by deleteEmptyParagraphMechanism
451 void fixCursorAfterDelete(LyXCursor & cur,
452 LyXCursor const & where);
454 /// delete double space (false) or empty paragraphs (true) around old_cursor
455 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
458 /** Updates all counters starting BEHIND the row. Changed paragraphs
459 * with a dynamic left margin will be rebroken. */
460 void updateCounters();
464 * Returns an inset if inset was hit, or 0 if not.
465 * If hit, the coordinates are changed relative to the inset.
467 InsetOld * checkInsetHit(int & x, int & y);
470 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
472 int singleWidth(ParagraphList::iterator pit,
473 lyx::pos_type pos, char c) const;
474 /// rebuild row cache
475 void rebuildRows(ParagraphList::iterator pit);
477 /// return the color of the canvas
478 LColor::color backgroundColor() const;
481 mutable bool bidi_same_direction;
483 unsigned char transformChar(unsigned char c, Paragraph const & par,
484 lyx::pos_type pos) const;
487 * Returns the left beginning of the text.
488 * This information cannot be taken from the layout object, because
489 * in LaTeX the beginning of the text fits in some cases
490 * (for example sections) exactly the label-width.
492 int leftMargin(Row const & row) const;
494 int rightMargin(Buffer const &, Row const & row) const;
496 /** this calculates the specified parameters. needed when setting
497 * the cursor and when creating a visible row */
498 void prepareToPrint(RowList::iterator row, int & x,
499 int & fill_separator,
501 int & fill_label_hfill,
502 bool bidi = true) const;
506 void setCounter(Buffer const *, ParagraphList::iterator pit);
508 void deleteWordForward();
510 void deleteWordBackward();
512 void deleteLineForward();
515 * some low level functions
519 /// return the pos value *before* which a row should break.
520 /// for example, the pos at which IsNewLine(pos) == true
521 lyx::pos_type rowBreakPoint(Row const & row) const;
523 /// returns the minimum space a row needs on the screen in pixel
524 int fill(RowList::iterator row, int workwidth) const;
527 * returns the minimum space a manual label needs on the
530 int labelFill(Row const & row) const;
533 int labelEnd(Row const & row) const;
536 mutable std::vector<lyx::pos_type> log2vis_list;
538 mutable std::vector<lyx::pos_type> vis2log_list;
540 mutable std::vector<lyx::pos_type> bidi_levels;
542 mutable lyx::pos_type bidi_start;
544 mutable lyx::pos_type bidi_end;
550 // special owner functions
552 ParagraphList & ownerParagraphs() const;
554 /// return true if this is owned by an inset.
555 bool isInInset() const;
558 /** Cursor related data.
559 Later this variable has to be removed. There should be now internal
562 ///TextCursor cursor_;
565 /// return the default height of a row in pixels, considering font zoom
566 extern int defaultRowHeight();