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, ParagraphList & plist);
56 void init(BufferView *);
61 /// the current font settings
64 LyXFont real_current_font;
65 /// our buffer's default layout font
68 InsetText * inset_owner;
70 /// update all cached row positions
71 void updateRowPositions();
73 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
75 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
77 LyXFont getLabelFont(ParagraphList::iterator pit) const;
79 void setCharFont(ParagraphList::iterator pit,
80 lyx::pos_type pos, LyXFont const & font);
81 void setCharFont(ParagraphList::iterator pit,
83 LyXFont const & font, bool toggleall);
85 /// what you expect when pressing <enter> at cursor position
86 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
88 /** set layout over selection and make a total rebreak of
91 ParagraphList::iterator
92 setLayout(LyXCursor & actual_cursor,
93 LyXCursor & selection_start,
94 LyXCursor & selection_end,
95 std::string const & layout);
97 void setLayout(std::string const & layout);
100 * Increase or decrease the nesting depth of the selected paragraph(s)
101 * if test_only, don't change any depths. Returns whether something
102 * (would have) changed
104 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
106 /// get the depth at current cursor position
107 int getDepth() const;
109 /** set font over selection and make a total rebreak of those
111 toggleall defaults to false.
113 void setFont(LyXFont const &, bool toggleall = false);
115 /// rebreaks all paragaphs between the given pars.
116 void redoParagraphs(ParagraphList::iterator begin,
117 ParagraphList::iterator end);
118 /// rebreaks the given par
119 void redoParagraph(ParagraphList::iterator pit);
121 /// rebreaks the cursor par
122 void redoParagraph();
124 /// rebreaks the given par
125 void redoParagraphInternal(ParagraphList::iterator pit);
129 void toggleFree(LyXFont const &, bool toggleall = false);
132 std::string getStringToIndex();
134 /** insert a character, moves all the following breaks in the
135 same Paragraph one to the right and make a little rebreak
137 void insertChar(char c);
139 void insertInset(InsetOld * inset);
141 /// a full rebreak of the whole text
143 /// compute text metrics
144 void metrics(MetricsInfo & mi, Dimension & dim);
147 DispatchResult dispatch(FuncRequest const & cmd);
151 BufferView * bv() const;
153 friend class LyXScreen;
156 /// only the top-level LyXText has this non-zero
157 BufferView * bv_owner;
159 /// returns an iterator pointing to a cursor paragraph
160 ParagraphList::iterator getPar(LyXCursor const & cursor) const;
162 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
164 int parOffset(ParagraphList::iterator pit) const;
166 ParagraphList::iterator cursorPar() const;
168 RowList::iterator cursorRow() const;
170 /** returns a pointer to the row near the specified y-coordinate
171 (relative to the whole text). y is set to the real beginning
174 RowList::iterator getRowNearY(int y,
175 ParagraphList::iterator & pit) const;
177 /** returns the column near the specified x-coordinate of the row
178 x is set to the real beginning of this column
180 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
181 Row const & row, int & x, bool & boundary) const;
183 /// need the selection cursor:
186 void clearSelection();
188 /// select the word we need depending on word_location
189 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
190 /// just selects the word the cursor is in
191 void selectWord(lyx::word_location loc);
192 /// returns the inset at cursor (if it exists), 0 otherwise
193 InsetOld * getInset() const;
195 /// accept selected change
198 /// reject selected change
201 /// re-computes the cached coordinates in the cursor
204 void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
205 /// returns true if par was empty and was removed
206 bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
207 bool setfont = true, bool boundary = false);
209 void setCursor(LyXCursor &, lyx::paroffset_type par,
210 lyx::pos_type pos, bool boundary = false);
212 void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
213 bool setfont = true, bool boundary = false);
215 void setCurrentFont();
218 void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
220 void recUndo(lyx::paroffset_type first) const;
222 void setCursorFromCoordinates(int x, int y);
224 void setCursorFromCoordinates(LyXCursor &, int x, int y);
226 void cursorUp(bool selecting = false);
228 void cursorDown(bool selecting = false);
230 void cursorLeft(bool internal = true);
232 void cursorRight(bool internal = true);
234 void cursorLeftOneWord();
236 void cursorRightOneWord();
238 void cursorUpParagraph();
240 void cursorDownParagraph();
246 void cursorPrevious();
258 bool selectWordWhenUnderCursor(lyx::word_location);
264 text_capitalization = 1,
268 /// Change the case of the word at cursor position.
269 void changeCase(TextCase action);
274 void cutSelection(bool doclear = true, bool realcut = true);
276 void copySelection();
278 void pasteSelection(size_t sel_index = 0);
280 /** the DTP switches for paragraphs. LyX will store the top settings
281 always in the first physical paragraph, the bottom settings in the
282 last. When a paragraph is broken, the top settings rest, the bottom
283 settings are given to the new one.
286 VSpace const & space_top,
287 VSpace const & space_bottom,
288 Spacing const & spacing,
290 std::string const & labelwidthstring,
293 /* these things are for search and replace */
296 * Sets the selection from the current cursor position to length
297 * characters to the right. No safety checks.
299 void setSelectionRange(lyx::pos_type length);
301 /** simple replacing. The font of the first selected character
304 void replaceSelectionWithString(std::string const & str);
306 /// needed to insert the selection
307 void insertStringAsLines(std::string const & str);
308 /// needed to insert the selection
309 void insertStringAsParagraphs(std::string const & str);
311 /// Find next inset of some specified type.
312 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
313 std::string const & contents = std::string());
315 void gotoInset(std::vector<InsetOld::Code> const & codes,
318 void gotoInset(InsetOld::Code code, bool same_content);
321 int workWidth() const;
325 float getCursorX(ParagraphList::iterator pit,
326 Row const & row, lyx::pos_type pos, bool boundary) const;
327 /// used in setlayout
328 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
330 /// Calculate and set the height of the row
331 void setHeightOfRow(ParagraphList::iterator, Row & row);
333 // fix the cursor `cur' after a characters has been deleted at `where'
334 // position. Called by deleteEmptyParagraphMechanism
335 void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
337 /// delete double space (false) or empty paragraphs (true) around old_cursor
338 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
341 /** Updates all counters starting BEHIND the row. Changed paragraphs
342 * with a dynamic left margin will be rebroken. */
343 void updateCounters();
345 * Returns an inset if inset was hit, or 0 if not.
347 InsetOld * checkInsetHit(int x, int y);
350 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
352 int singleWidth(ParagraphList::iterator pit,
353 lyx::pos_type pos, char c, LyXFont const & Font) const;
355 /// return the color of the canvas
356 LColor_color backgroundColor() const;
359 * Returns the left beginning of the text.
360 * This information cannot be taken from the layout object, because
361 * in LaTeX the beginning of the text fits in some cases
362 * (for example sections) exactly the label-width.
364 int leftMargin(ParagraphList::iterator pit, Row const & row) const;
366 int rightMargin(Paragraph const & par, Buffer const &) const;
368 /** this calculates the specified parameters. needed when setting
369 * the cursor and when creating a visible row */
370 void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
374 void setCounter(Buffer const &, ParagraphList::iterator pit);
376 void deleteWordForward();
378 void deleteWordBackward();
380 void deleteLineForward();
382 /// sets row.end to the pos value *after* which a row should break.
383 /// for example, the pos after which isNewLine(pos) == true
384 void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
386 /// sets row.witdh to the minimum space a row needs on the screen in pixel
387 void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
390 * returns the minimum space a manual label needs on the
393 int labelFill(ParagraphList::iterator pit, Row const & row) const;
396 int labelEnd(ParagraphList::iterator pit, Row const & row) const;
400 /// set 'number' font property
402 /// is the cursor paragraph right-to-left?
411 ParagraphList * paragraphs_;
413 // special owner functions
415 ParagraphList & ownerParagraphs() const;
417 /// return true if this is owned by an inset.
418 bool isInInset() const;
420 /// return first row of text
421 RowList::iterator firstRow() const;
422 /// return last row of text
423 RowList::iterator lastRow() const;
424 /// return row "behind" last row of text
425 RowList::iterator endRow() const;
426 /// return next row crossing paragraph boundaries
427 void nextRow(ParagraphList::iterator & pit,
428 RowList::iterator & rit) const;
429 /// return previous row crossing paragraph boundaries
430 void previousRow(ParagraphList::iterator & pit,
431 RowList::iterator & rit) const;
433 /// is this row the last in the text?
434 bool isLastRow(ParagraphList::iterator pit, Row const & row) const;
435 /// is this row the first in the text?
436 bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
439 std::string selectionAsString(Buffer const & buffer, bool label) const;
441 double spacing(Paragraph const &) const;
443 /** Cursor related data.
444 Later this variable has to be removed. There should be now internal
447 ///TextCursor cursor_;
448 /// prohibit this as long as there are back pointers...
449 LyXText(LyXText const &);
451 // cache for cursorPar()
452 mutable ParagraphList::iterator cache_par_;
453 mutable int cache_pos_;
456 /// return the default height of a row in pixels, considering font zoom
457 extern int defaultRowHeight();