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.
17 #include "bufferview_funcs.h"
21 #include "ParagraphList_fwd.h"
22 #include "RowList_fwd.h"
23 #include "textcursor.h"
25 #include "insets/inset.h"
43 This class used to hold the mapping between buffer paragraphs and
44 screen rows. Nowadays, the Paragraphs take care of their rows
45 themselves and this contains just most of the code for manipulating
46 them and interaction with the Cursor.
49 // The inheritance from TextCursor should go. It's just there to ease
51 class LyXText : public TextCursor {
54 LyXText(BufferView *, InsetText *, bool ininset,
55 ParagraphList & paragraphs);
57 void init(BufferView *);
62 /// the current font settings
65 LyXFont real_current_font;
66 /// our buffer's default layout font
69 InsetText * inset_owner;
71 UpdatableInset * the_locking_inset;
73 /// update all cached row positions
74 void updateRowPositions();
76 int getRealCursorX() const;
78 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
80 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
82 LyXFont getLabelFont(ParagraphList::iterator pit) const;
84 void setCharFont(ParagraphList::iterator pit,
85 lyx::pos_type pos, LyXFont const & font);
86 void setCharFont(ParagraphList::iterator pit,
88 LyXFont const & font, bool toggleall);
90 /// what you expect when pressing <enter> at cursor position
91 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
93 /** set layout over selection and make a total rebreak of
96 ParagraphList::iterator
97 setLayout(LyXCursor & actual_cursor,
98 LyXCursor & selection_start,
99 LyXCursor & selection_end,
100 std::string const & layout);
102 void setLayout(std::string const & layout);
105 * Increase or decrease the nesting depth of the selected paragraph(s)
106 * if test_only, don't change any depths. Returns whether something
107 * (would have) changed
109 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
111 /// get the depth at current cursor position
112 int getDepth() const;
114 /** set font over selection and make a total rebreak of those
116 toggleall defaults to false.
118 void setFont(LyXFont const &, bool toggleall = false);
120 /// rebreaks all paragaphs between the given pars.
121 void redoParagraphs(ParagraphList::iterator begin,
122 ParagraphList::iterator end);
123 /// rebreaks the given par
124 void redoParagraph(ParagraphList::iterator pit);
126 /// rebreaks the cursor par
127 void redoParagraph();
129 /// rebreaks the given par
130 void redoParagraphInternal(ParagraphList::iterator pit);
134 void toggleFree(LyXFont const &, bool toggleall = false);
137 std::string getStringToIndex();
139 /** insert a character, moves all the following breaks in the
140 same Paragraph one to the right and make a little rebreak
142 void insertChar(char c);
144 void insertInset(InsetOld * inset);
146 /// a full rebreak of the whole text
148 /// compute text metrics
149 void metrics(MetricsInfo & mi, Dimension & dim);
152 DispatchResult dispatch(FuncRequest const & cmd);
156 BufferView * bv() const;
158 friend class LyXScreen;
161 /// only the top-level LyXText has this non-zero
162 BufferView * bv_owner;
164 /// returns an iterator pointing to a cursor paragraph
165 ParagraphList::iterator getPar(LyXCursor const & cursor) const;
167 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
169 int parOffset(ParagraphList::iterator pit) const;
171 ParagraphList::iterator cursorPar() const;
173 RowList::iterator cursorRow() const;
175 /** returns a pointer to the row near the specified y-coordinate
176 (relative to the whole text). y is set to the real beginning
179 RowList::iterator getRowNearY(int y,
180 ParagraphList::iterator & pit) const;
182 /** returns the column near the specified x-coordinate of the row
183 x is set to the real beginning of this column
185 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
186 Row const & row, int & x, bool & boundary) const;
188 /// need the selection cursor:
191 void clearSelection();
193 /// select the word we need depending on word_location
194 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
195 /// just selects the word the cursor is in
196 void selectWord(lyx::word_location loc);
197 /// returns the inset at cursor (if it exists), 0 otherwise
198 InsetOld * getInset() const;
200 /// accept selected change
203 /// reject selected change
206 /// re-computes the cached coordinates in the cursor
209 void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
210 /// returns true if par was empty and was removed
211 bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
212 bool setfont = true, bool boundary = false);
214 void setCursor(LyXCursor &, lyx::paroffset_type par,
215 lyx::pos_type pos, bool boundary = false);
217 void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
218 bool setfont = true, bool boundary = false);
220 void setCurrentFont();
223 void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
225 void recUndo(lyx::paroffset_type first) const;
227 void setCursorFromCoordinates(int x, int y);
229 void setCursorFromCoordinates(LyXCursor &, int x, int y);
231 void cursorUp(bool selecting = false);
233 void cursorDown(bool selecting = false);
235 void cursorLeft(bool internal = true);
237 void cursorRight(bool internal = true);
239 void cursorLeftOneWord();
241 void cursorRightOneWord();
243 void cursorUpParagraph();
245 void cursorDownParagraph();
251 void cursorPrevious();
263 bool selectWordWhenUnderCursor(lyx::word_location);
269 text_capitalization = 1,
273 /// Change the case of the word at cursor position.
274 void changeCase(TextCase action);
279 void cutSelection(bool doclear = true, bool realcut = true);
281 void copySelection();
283 void pasteSelection(size_t sel_index = 0);
285 /** the DTP switches for paragraphs. LyX will store the top settings
286 always in the first physical paragraph, the bottom settings in the
287 last. When a paragraph is broken, the top settings rest, the bottom
288 settings are given to the new one.
291 VSpace const & space_top,
292 VSpace const & space_bottom,
293 Spacing const & spacing,
295 std::string const & labelwidthstring,
298 /* these things are for search and replace */
301 * Sets the selection from the current cursor position to length
302 * characters to the right. No safety checks.
304 void setSelectionRange(lyx::pos_type length);
306 /** simple replacing. The font of the first selected character
309 void replaceSelectionWithString(std::string const & str);
311 /// needed to insert the selection
312 void insertStringAsLines(std::string const & str);
313 /// needed to insert the selection
314 void insertStringAsParagraphs(std::string const & str);
316 /// Find next inset of some specified type.
317 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
318 std::string const & contents = std::string());
320 void gotoInset(std::vector<InsetOld::Code> const & codes,
323 void gotoInset(InsetOld::Code code, bool same_content);
326 int workWidth() const;
330 float getCursorX(ParagraphList::iterator pit,
331 Row const & row, lyx::pos_type pos, bool boundary) const;
332 /// used in setlayout
333 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
335 /// Calculate and set the height of the row
336 void setHeightOfRow(ParagraphList::iterator, Row & row);
338 // fix the cursor `cur' after a characters has been deleted at `where'
339 // position. Called by deleteEmptyParagraphMechanism
340 void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
342 /// delete double space (false) or empty paragraphs (true) around old_cursor
343 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
346 /** Updates all counters starting BEHIND the row. Changed paragraphs
347 * with a dynamic left margin will be rebroken. */
348 void updateCounters();
350 * Returns an inset if inset was hit, or 0 if not.
351 * If hit, the coordinates are changed relative to the inset.
353 InsetOld * checkInsetHit(int & x, int & y);
356 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
358 int singleWidth(ParagraphList::iterator pit,
359 lyx::pos_type pos, char c, LyXFont const & Font) const;
361 /// return the color of the canvas
362 LColor_color backgroundColor() const;
365 * Returns the left beginning of the text.
366 * This information cannot be taken from the layout object, because
367 * in LaTeX the beginning of the text fits in some cases
368 * (for example sections) exactly the label-width.
370 int leftMargin(ParagraphList::iterator pit, Row const & row) const;
372 int rightMargin(Paragraph const & par, Buffer const &) const;
374 /** this calculates the specified parameters. needed when setting
375 * the cursor and when creating a visible row */
376 void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
380 void setCounter(Buffer const &, ParagraphList::iterator pit);
382 void deleteWordForward();
384 void deleteWordBackward();
386 void deleteLineForward();
388 /// sets row.end to the pos value *after* which a row should break.
389 /// for example, the pos after which isNewLine(pos) == true
390 void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
392 /// sets row.witdh to the minimum space a row needs on the screen in pixel
393 void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
396 * returns the minimum space a manual label needs on the
399 int labelFill(ParagraphList::iterator pit, Row const & row) const;
402 int labelEnd(ParagraphList::iterator pit, Row const & row) const;
413 ParagraphList * paragraphs_;
415 // special owner functions
417 ParagraphList & ownerParagraphs() const;
419 /// return true if this is owned by an inset.
420 bool isInInset() const;
422 /// return first row of text
423 RowList::iterator firstRow() const;
424 /// return last row of text
425 RowList::iterator lastRow() const;
426 /// return row "behind" last row of text
427 RowList::iterator endRow() const;
428 /// return next row crossing paragraph boundaries
429 void nextRow(ParagraphList::iterator & pit,
430 RowList::iterator & rit) const;
431 /// return previous row crossing paragraph boundaries
432 void previousRow(ParagraphList::iterator & pit,
433 RowList::iterator & rit) const;
435 /// is this row the last in the text?
436 bool isLastRow(ParagraphList::iterator pit, Row const & row) const;
437 /// is this row the first in the text?
438 bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
441 std::string selectionAsString(Buffer const & buffer, bool label) const;
443 double spacing(Paragraph const &) const;
445 /** Cursor related data.
446 Later this variable has to be removed. There should be now internal
449 ///TextCursor cursor_;
450 /// prohibit this as long as there are back pointers...
451 LyXText(LyXText const &);
453 // cache for cursorPar()
454 mutable ParagraphList::iterator cache_par_;
455 mutable int cache_pos_;
458 /// return the default height of a row in pixels, considering font zoom
459 extern int defaultRowHeight();