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);
103 void breakAgainOneRow(RowList::iterator rit);
104 /// what you expect when pressing <enter> at cursor position
105 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
107 /** set layout over selection and make a total rebreak of
110 ParagraphList::iterator
111 setLayout(LyXCursor & actual_cursor,
112 LyXCursor & selection_start,
113 LyXCursor & selection_end,
114 string const & layout);
116 void setLayout(string const & layout);
119 * Increase or decrease the nesting depth of the selected paragraph(s)
120 * if test_only, don't change any depths. Returns whether something
121 * (would have) changed
123 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
125 /// get the depth at current cursor position
126 int getDepth() const;
128 /** set font over selection and make a total rebreak of those
130 toggleall defaults to false.
132 void setFont(LyXFont const &, bool toggleall = false);
134 /// rebreaks all paragaphs between the given pars.
135 void redoParagraphs(ParagraphList::iterator begin,
136 ParagraphList::iterator end);
137 /// rebreaks the given par
138 void redoParagraph(ParagraphList::iterator pit);
139 /// rebreaks the cursor par
140 void redoParagraph();
141 /// returns first row belongin to some par
142 RowList::iterator firstRow(ParagraphList::iterator pit);
145 void toggleFree(LyXFont const &, bool toggleall = false);
148 string getStringToIndex();
150 /** recalculates the heights of all previous rows of the
151 specified paragraph. needed, if the last characters font
154 void redoHeightOfParagraph();
156 /** insert a character, moves all the following breaks in the
157 same Paragraph one to the right and make a little rebreak
159 void insertChar(char c);
161 void insertInset(InsetOld * inset);
163 /// Completes the insertion with a rebreak
164 void partialRebreak();
165 /// a full rebreak of the whole text
167 /// compute text metrics
168 void metrics(MetricsInfo & mi, Dimension & dim);
171 InsetOld::RESULT dispatch(FuncRequest const & cmd);
175 BufferView * bv() const;
177 friend class LyXScreen;
180 /// only the top-level LyXText has this non-zero
181 BufferView * bv_owner;
184 /// returns a pointer to a specified row.
186 getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
188 /// returns a pointer cursor row
189 RowList::iterator getRow(LyXCursor const & cursor) const;
191 RowList::iterator cursorRow() const;
193 * Return the next row, when cursor is at the end of the
194 * previous row, for insets that take a full row.
196 * FIXME: explain why we need this ? especially for y...
198 RowList::iterator cursorIRow() const;
200 /** returns a pointer to the row near the specified y-coordinate
201 (relative to the whole text). y is set to the real beginning
204 RowList::iterator getRowNearY(int & y) const;
206 /** returns the column near the specified x-coordinate of the row
207 x is set to the real beginning of this column
209 lyx::pos_type getColumnNearX(RowList::iterator rit,
210 int & x, bool & boundary) const;
212 /** returns a pointer to a specified row. y is set to the beginning
216 getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
218 RowList & rows() const {
223 /// need the selection cursor:
226 void clearSelection();
228 /// select the word we need depending on word_location
229 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
230 /// just selects the word the cursor is in
231 void selectWord(lyx::word_location loc);
232 /// returns the inset at cursor (if it exists), 0 otherwise
233 InsetOld * getInset() const;
235 /// accept selected change
238 /// reject selected change
241 /** 'selects" the next word, where the cursor is not in
242 and returns this word as string. THe cursor will be moved
243 to the beginning of this word.
244 With SelectSelectedWord can this be highlighted really
246 WordLangTuple const selectNextWordToSpellcheck(float & value);
248 void selectSelectedWord();
249 /// returns true if par was empty and was removed
250 bool setCursor(ParagraphList::iterator pit,
253 bool boundary = false);
255 void setCursor(LyXCursor &, ParagraphList::iterator pit,
257 bool boundary = false);
259 void setCursorIntern(ParagraphList::iterator pit,
262 bool boundary = false);
264 void setCurrentFont();
267 bool isBoundary(Buffer const *, Paragraph const & par,
268 lyx::pos_type pos) const;
270 bool isBoundary(Buffer const *, Paragraph const & par,
272 LyXFont const & font) const;
275 void setCursorFromCoordinates(int x, int y);
277 void setCursorFromCoordinates(LyXCursor &,
280 void cursorUp(bool selecting = false);
282 void cursorDown(bool selecting = false);
284 void cursorLeft(bool internal = true);
286 void cursorRight(bool internal = true);
288 void cursorLeftOneWord();
290 void cursorRightOneWord();
292 void cursorUpParagraph();
294 void cursorDownParagraph();
300 void cursorPrevious();
312 bool selectWordWhenUnderCursor(lyx::word_location);
318 text_capitalization = 1,
322 /// Change the case of the word at cursor position.
323 void changeCase(TextCase action);
328 void cutSelection(bool doclear = true, bool realcut = true);
330 void copySelection();
332 void pasteSelection(size_t sel_index = 0);
334 /** the DTP switches for paragraphs. LyX will store the top settings
335 always in the first physical paragraph, the bottom settings in the
336 last. When a paragraph is broken, the top settings rest, the bottom
337 settings are given to the new one. So I can make shure, they do not
338 duplicate themself (and you cannnot make dirty things with them! )
340 void setParagraph(bool line_top, bool line_bottom,
341 bool pagebreak_top, bool pagebreak_bottom,
342 VSpace const & space_top,
343 VSpace const & space_bottom,
344 Spacing const & spacing,
346 string const & labelwidthstring,
349 /* these things are for search and replace */
352 * Sets the selection from the current cursor position to length
353 * characters to the right. No safety checks.
355 void setSelectionRange(lyx::pos_type length);
357 /** simple replacing. The font of the first selected character
360 void replaceSelectionWithString(string const & str);
362 /// needed to insert the selection
363 void insertStringAsLines(string const & str);
364 /// needed to insert the selection
365 void insertStringAsParagraphs(string const & str);
367 /// Find next inset of some specified type.
368 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
369 string const & contents = string());
371 void gotoInset(std::vector<InsetOld::Code> const & codes,
374 void gotoInset(InsetOld::Code code, bool same_content);
377 /* for the greater insets */
379 /// returns false if inset wasn't found
380 bool updateInset(InsetOld *);
382 void checkParagraph(ParagraphList::iterator pit, lyx::pos_type pos);
384 int workWidth() const;
387 void computeBidiTables(Buffer const *, RowList::iterator row) const;
388 /// Maps positions in the visual string to positions in logical string.
389 lyx::pos_type log2vis(lyx::pos_type pos) const;
390 /// Maps positions in the logical string to positions in visual string.
391 lyx::pos_type vis2log(lyx::pos_type pos) const;
393 lyx::pos_type bidi_level(lyx::pos_type pos) const;
395 bool bidi_InRange(lyx::pos_type pos) const;
398 mutable RowList rowlist_;
401 float getCursorX(RowList::iterator rit, lyx::pos_type pos,
402 lyx::pos_type last, bool boundary) const;
403 /// used in setlayout
404 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
406 /** forces the redrawing of a paragraph. Needed when manipulating a
409 void redoDrawingOfParagraph(LyXCursor const & cursor);
411 /// removes the row and reset the touched counters
412 void removeRow(RowList::iterator rit);
414 /// remove all following rows of the paragraph of the specified row.
415 void removeParagraph(RowList::iterator rit);
417 /// insert the specified paragraph behind the specified row
418 void insertParagraph(ParagraphList::iterator pit,
419 RowList::iterator rowit);
421 /** appends the implizit specified paragraph behind the specified row,
422 * start at the implizit given position */
423 void appendParagraph(RowList::iterator rowit);
426 void breakAgain(RowList::iterator rit);
427 /// Calculate and set the height of the row
428 void setHeightOfRow(RowList::iterator rit);
430 // fix the cursor `cur' after a characters has been deleted at `where'
431 // position. Called by deleteEmptyParagraphMechanism
432 void fixCursorAfterDelete(LyXCursor & cur,
433 LyXCursor const & where);
435 /// delete double space (false) or empty paragraphs (true) around old_cursor
436 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
439 /** Updates all counters starting BEHIND the row. Changed paragraphs
440 * with a dynamic left margin will be rebroken. */
441 void updateCounters();
445 * Returns an inset if inset was hit, or 0 if not.
446 * If hit, the coordinates are changed relative to the inset.
448 InsetOld * checkInsetHit(int & x, int & y);
451 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
453 int singleWidth(ParagraphList::iterator pit,
454 lyx::pos_type pos, char c) const;
455 /// rebuild row cache
456 void rebuildRows(ParagraphList::iterator pit);
458 /// return the color of the canvas
459 LColor::color backgroundColor() const;
462 mutable bool bidi_same_direction;
464 unsigned char transformChar(unsigned char c, Paragraph const & par,
465 lyx::pos_type pos) const;
468 * Returns the left beginning of the text.
469 * This information cannot be taken from the layout object, because
470 * in LaTeX the beginning of the text fits in some cases
471 * (for example sections) exactly the label-width.
473 int leftMargin(Row const & row) const;
475 int rightMargin(Buffer const &, Row const & row) const;
477 /** this calculates the specified parameters. needed when setting
478 * the cursor and when creating a visible row */
479 void prepareToPrint(RowList::iterator row, double & x,
480 double & fill_separator,
482 double & fill_label_hfill,
483 bool bidi = true) const;
487 void setCounter(Buffer const *, ParagraphList::iterator pit);
489 void deleteWordForward();
491 void deleteWordBackward();
493 void deleteLineForward();
496 * some low level functions
500 /// return the pos value *before* which a row should break.
501 /// for example, the pos at which IsNewLine(pos) == true
502 lyx::pos_type rowBreakPoint(Row const & row) const;
504 /// returns the minimum space a row needs on the screen in pixel
505 int fill(RowList::iterator row, int workwidth) const;
508 * returns the minimum space a manual label needs on the
511 int labelFill(Row const & row) const;
514 int labelEnd(Row const & row) const;
517 mutable std::vector<lyx::pos_type> log2vis_list;
519 mutable std::vector<lyx::pos_type> vis2log_list;
521 mutable std::vector<lyx::pos_type> bidi_levels;
523 mutable lyx::pos_type bidi_start;
525 mutable lyx::pos_type bidi_end;
531 // special owner functions
533 ParagraphList & ownerParagraphs() const;
535 /// return true if this is owned by an inset.
536 bool isInInset() const;
539 /** Cursor related data.
540 Later this variable has to be removed. There should be now internal
543 ///TextCursor cursor_;
546 /// return the default height of a row in pixels, considering font zoom
547 extern int defaultRowHeight();