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;
63 /// our buffer's default layout font
66 /** the 'anchor' row: the position of this row remains constant
67 * with respect to the top of the screen
69 RowList::iterator anchor_row_;
70 /** the pixel offset with respect to this row of top_y
72 int anchor_row_offset_;
74 /// update all cached row positions
75 void updateRowPositions();
76 /// get the y coord. of the top of the screen (relative to doc start)
78 /// set the y coord. of the top of the screen (relative to doc start)
80 /// set the anchoring row. top_y will be computed relative to this
81 void anchor_row(RowList::iterator rit);
83 InsetText * inset_owner;
85 UpdatableInset * the_locking_inset;
88 int getRealCursorX() const;
90 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
92 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
94 LyXFont getLabelFont(ParagraphList::iterator pit) const;
96 void setCharFont(ParagraphList::iterator pit,
97 lyx::pos_type pos, LyXFont const & font);
98 void setCharFont(ParagraphList::iterator pit,
100 LyXFont const & font, bool toggleall);
102 /// what you expect when pressing <enter> at cursor position
103 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
105 /** set layout over selection and make a total rebreak of
108 ParagraphList::iterator
109 setLayout(LyXCursor & actual_cursor,
110 LyXCursor & selection_start,
111 LyXCursor & selection_end,
112 string const & layout);
114 void setLayout(string const & layout);
117 * Increase or decrease the nesting depth of the selected paragraph(s)
118 * if test_only, don't change any depths. Returns whether something
119 * (would have) changed
121 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
123 /// get the depth at current cursor position
124 int getDepth() const;
126 /** set font over selection and make a total rebreak of those
128 toggleall defaults to false.
130 void setFont(LyXFont const &, bool toggleall = false);
132 /// rebreaks all paragaphs between the given pars.
133 void redoParagraphs(ParagraphList::iterator begin,
134 ParagraphList::iterator end);
135 /// rebreaks the given par
136 void redoParagraph(ParagraphList::iterator pit);
137 /// rebreaks the cursor par
138 void redoParagraph();
139 /// returns first row belongin to some par
140 RowList::iterator firstRow(ParagraphList::iterator pit);
143 void toggleFree(LyXFont const &, bool toggleall = false);
146 string getStringToIndex();
148 /** insert a character, moves all the following breaks in the
149 same Paragraph one to the right and make a little rebreak
151 void insertChar(char c);
153 void insertInset(InsetOld * inset);
155 /// a full rebreak of the whole text
157 /// compute text metrics
158 void metrics(MetricsInfo & mi, Dimension & dim);
161 InsetOld::RESULT dispatch(FuncRequest const & cmd);
165 BufferView * bv() const;
167 friend class LyXScreen;
170 /// only the top-level LyXText has this non-zero
171 BufferView * bv_owner;
174 /// returns a pointer to a specified row.
176 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
178 /// returns a pointer cursor row
179 RowList::iterator getRow(LyXCursor const & cursor) const;
181 RowList::iterator cursorRow() const;
183 * Return the next row, when cursor is at the end of the
184 * previous row, for insets that take a full row.
186 * FIXME: explain why we need this ? especially for y...
188 RowList::iterator cursorIRow() const;
190 /** returns a pointer to the row near the specified y-coordinate
191 (relative to the whole text). y is set to the real beginning
194 RowList::iterator getRowNearY(int & y) const;
196 /** returns the column near the specified x-coordinate of the row
197 x is set to the real beginning of this column
199 lyx::pos_type getColumnNearX(RowList::iterator rit,
200 int & x, bool & boundary) const;
202 /** returns a pointer to a specified row. y is set to the beginning
206 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
208 RowList & rows() const {
213 /// need the selection cursor:
216 void clearSelection();
218 /// select the word we need depending on word_location
219 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
220 /// just selects the word the cursor is in
221 void selectWord(lyx::word_location loc);
222 /// returns the inset at cursor (if it exists), 0 otherwise
223 InsetOld * getInset() const;
225 /// accept selected change
228 /// reject selected change
231 /** 'selects" the next word, where the cursor is not in
232 and returns this word as string. THe cursor will be moved
233 to the beginning of this word.
234 With SelectSelectedWord can this be highlighted really
236 WordLangTuple const selectNextWordToSpellcheck(float & value);
238 void selectSelectedWord();
239 /// re-computes the cached coordinates in the cursor
241 /// returns true if par was empty and was removed
242 bool setCursor(ParagraphList::iterator pit,
245 bool boundary = false);
247 void setCursor(LyXCursor &, ParagraphList::iterator pit,
249 bool boundary = false);
251 void setCursorIntern(ParagraphList::iterator pit,
254 bool boundary = false);
256 void setCurrentFont();
259 bool isBoundary(Buffer const *, Paragraph const & par,
260 lyx::pos_type pos) const;
262 bool isBoundary(Buffer const *, Paragraph const & par,
264 LyXFont const & font) const;
267 void setCursorFromCoordinates(int x, int y);
269 void setCursorFromCoordinates(LyXCursor &,
272 void cursorUp(bool selecting = false);
274 void cursorDown(bool selecting = false);
276 void cursorLeft(bool internal = true);
278 void cursorRight(bool internal = true);
280 void cursorLeftOneWord();
282 void cursorRightOneWord();
284 void cursorUpParagraph();
286 void cursorDownParagraph();
292 void cursorPrevious();
304 bool selectWordWhenUnderCursor(lyx::word_location);
310 text_capitalization = 1,
314 /// Change the case of the word at cursor position.
315 void changeCase(TextCase action);
320 void cutSelection(bool doclear = true, bool realcut = true);
322 void copySelection();
324 void pasteSelection(size_t sel_index = 0);
326 /** the DTP switches for paragraphs. LyX will store the top settings
327 always in the first physical paragraph, the bottom settings in the
328 last. When a paragraph is broken, the top settings rest, the bottom
329 settings are given to the new one. So I can make shure, they do not
330 duplicate themself (and you cannnot make dirty things with them! )
332 void setParagraph(bool line_top, bool line_bottom,
333 bool pagebreak_top, bool pagebreak_bottom,
334 VSpace const & space_top,
335 VSpace const & space_bottom,
336 Spacing const & spacing,
338 string const & labelwidthstring,
341 /* these things are for search and replace */
344 * Sets the selection from the current cursor position to length
345 * characters to the right. No safety checks.
347 void setSelectionRange(lyx::pos_type length);
349 /** simple replacing. The font of the first selected character
352 void replaceSelectionWithString(string const & str);
354 /// needed to insert the selection
355 void insertStringAsLines(string const & str);
356 /// needed to insert the selection
357 void insertStringAsParagraphs(string const & str);
359 /// Find next inset of some specified type.
360 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
361 string const & contents = string());
363 void gotoInset(std::vector<InsetOld::Code> const & codes,
366 void gotoInset(InsetOld::Code code, bool same_content);
369 int workWidth() const;
372 void computeBidiTables(Buffer const *, RowList::iterator row) const;
373 /// Maps positions in the visual string to positions in logical string.
374 lyx::pos_type log2vis(lyx::pos_type pos) const;
375 /// Maps positions in the logical string to positions in visual string.
376 lyx::pos_type vis2log(lyx::pos_type pos) const;
378 lyx::pos_type bidi_level(lyx::pos_type pos) const;
380 bool bidi_InRange(lyx::pos_type pos) const;
383 mutable RowList rowlist_;
386 float getCursorX(RowList::iterator rit, lyx::pos_type pos,
387 lyx::pos_type last, bool boundary) const;
388 /// used in setlayout
389 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
391 /** forces the redrawing of a paragraph. Needed when manipulating a
394 void redoDrawingOfParagraph(LyXCursor const & cursor);
396 /// removes the row and reset the touched counters
397 void removeRow(RowList::iterator rit);
399 /// remove all following rows of the paragraph of the specified row.
400 void removeParagraph(RowList::iterator rit);
402 /// insert the specified paragraph behind the specified row
403 void insertParagraph(ParagraphList::iterator pit,
404 RowList::iterator rowit);
406 /// Calculate and set the height of the row
407 void setHeightOfRow(RowList::iterator rit);
409 // fix the cursor `cur' after a characters has been deleted at `where'
410 // position. Called by deleteEmptyParagraphMechanism
411 void fixCursorAfterDelete(LyXCursor & cur,
412 LyXCursor const & where);
414 /// delete double space (false) or empty paragraphs (true) around old_cursor
415 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
418 /** Updates all counters starting BEHIND the row. Changed paragraphs
419 * with a dynamic left margin will be rebroken. */
420 void updateCounters();
422 * Returns an inset if inset was hit, or 0 if not.
423 * If hit, the coordinates are changed relative to the inset.
425 InsetOld * checkInsetHit(int & x, int & y);
428 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
430 int singleWidth(ParagraphList::iterator pit,
431 lyx::pos_type pos, char c) const;
432 /// rebuild row cache
433 void rebuildRows(ParagraphList::iterator pit);
435 /// return the color of the canvas
436 LColor::color backgroundColor() const;
439 mutable bool bidi_same_direction;
441 unsigned char transformChar(unsigned char c, Paragraph const & par,
442 lyx::pos_type pos) const;
445 * Returns the left beginning of the text.
446 * This information cannot be taken from the layout object, because
447 * in LaTeX the beginning of the text fits in some cases
448 * (for example sections) exactly the label-width.
450 int leftMargin(Row const & row) const;
452 int rightMargin(Buffer const &, Row const & row) const;
454 /** this calculates the specified parameters. needed when setting
455 * the cursor and when creating a visible row */
456 void prepareToPrint(RowList::iterator row, double & x,
457 double & fill_separator,
459 double & fill_label_hfill,
460 bool bidi = true) const;
464 void setCounter(Buffer const *, ParagraphList::iterator pit);
466 void deleteWordForward();
468 void deleteWordBackward();
470 void deleteLineForward();
473 * some low level functions
477 /// return the pos value *before* which a row should break.
478 /// for example, the pos at which IsNewLine(pos) == true
479 lyx::pos_type rowBreakPoint(Row const & row) const;
481 /// returns the minimum space a row needs on the screen in pixel
482 int fill(RowList::iterator row, int workwidth) const;
485 * returns the minimum space a manual label needs on the
488 int labelFill(Row const & row) const;
491 int labelEnd(Row const & row) const;
494 mutable std::vector<lyx::pos_type> log2vis_list;
496 mutable std::vector<lyx::pos_type> vis2log_list;
498 mutable std::vector<lyx::pos_type> bidi_levels;
500 mutable lyx::pos_type bidi_start;
502 mutable lyx::pos_type bidi_end;
508 // special owner functions
510 ParagraphList & ownerParagraphs() const;
512 /// return true if this is owned by an inset.
513 bool isInInset() 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();