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"
44 This class used to hold the mapping between buffer paragraphs and
45 screen rows. Nowadays, the Paragraphs take care of their rows
46 themselves and this contains just most of the code for manipulating
47 them and interaction with the Cursor.
50 // The inheritance from TextCursor should go. It's just there to ease
52 class LyXText : public TextCursor {
55 LyXText(BufferView *, InsetText *, bool ininset,
56 ParagraphList & paragraphs);
58 void init(BufferView *);
63 /// the current font settings
66 LyXFont real_current_font;
67 /// our buffer's default layout font
70 /// offset of drawn area to document start.
73 /// update all cached row positions
74 void updateRowPositions();
76 InsetText * inset_owner;
78 UpdatableInset * the_locking_inset;
81 int getRealCursorX() const;
83 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
85 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
87 LyXFont getLabelFont(ParagraphList::iterator pit) const;
89 void setCharFont(ParagraphList::iterator pit,
90 lyx::pos_type pos, LyXFont const & font);
91 void setCharFont(ParagraphList::iterator pit,
93 LyXFont const & font, bool toggleall);
95 /// what you expect when pressing <enter> at cursor position
96 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
98 /** set layout over selection and make a total rebreak of
101 ParagraphList::iterator
102 setLayout(LyXCursor & actual_cursor,
103 LyXCursor & selection_start,
104 LyXCursor & selection_end,
105 std::string const & layout);
107 void setLayout(std::string const & layout);
110 * Increase or decrease the nesting depth of the selected paragraph(s)
111 * if test_only, don't change any depths. Returns whether something
112 * (would have) changed
114 bool changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only);
116 /// get the depth at current cursor position
117 int getDepth() const;
119 /** set font over selection and make a total rebreak of those
121 toggleall defaults to false.
123 void setFont(LyXFont const &, bool toggleall = false);
125 /// rebreaks all paragaphs between the given pars.
126 void redoParagraphs(ParagraphList::iterator begin,
127 ParagraphList::iterator end);
128 /// rebreaks the given par
129 void redoParagraph(ParagraphList::iterator pit);
131 /// rebreaks the cursor par
132 void redoParagraph();
134 /// rebreaks the given par
135 void redoParagraphInternal(ParagraphList::iterator pit);
139 void toggleFree(LyXFont const &, bool toggleall = false);
142 std::string getStringToIndex();
144 /** insert a character, moves all the following breaks in the
145 same Paragraph one to the right and make a little rebreak
147 void insertChar(char c);
149 void insertInset(InsetOld * inset);
151 /// a full rebreak of the whole text
153 /// compute text metrics
154 void metrics(MetricsInfo & mi, Dimension & dim);
157 dispatch_result dispatch(FuncRequest const & cmd);
161 BufferView * bv() const;
163 friend class LyXScreen;
166 /// only the top-level LyXText has this non-zero
167 BufferView * bv_owner;
169 /// returns an iterator pointing to a cursor paragraph
170 ParagraphList::iterator getPar(LyXCursor const & cursor) const;
172 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
174 int parOffset(ParagraphList::iterator pit) const;
176 ParagraphList::iterator cursorPar() const;
178 RowList::iterator cursorRow() const;
180 /** returns a pointer to the row near the specified y-coordinate
181 (relative to the whole text). y is set to the real beginning
184 RowList::iterator getRowNearY(int y,
185 ParagraphList::iterator & pit) const;
187 /** returns the column near the specified x-coordinate of the row
188 x is set to the real beginning of this column
190 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
191 Row const & row, int & x, bool & boundary) const;
193 /// need the selection cursor:
196 void clearSelection();
198 /// select the word we need depending on word_location
199 void getWord(LyXCursor & from, LyXCursor & to, lyx::word_location const);
200 /// just selects the word the cursor is in
201 void selectWord(lyx::word_location loc);
202 /// returns the inset at cursor (if it exists), 0 otherwise
203 InsetOld * getInset() const;
205 /// accept selected change
208 /// reject selected change
211 /** 'selects" the next word, where the cursor is not in
212 and returns this word as string. THe cursor will be moved
213 to the beginning of this word.
214 With SelectSelectedWord can this be highlighted really
216 WordLangTuple const selectNextWordToSpellcheck(float & value);
218 void selectSelectedWord();
219 /// re-computes the cached coordinates in the cursor
222 void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
223 /// returns true if par was empty and was removed
224 bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
225 bool setfont = true, bool boundary = false);
227 void setCursor(LyXCursor &, lyx::paroffset_type par,
228 lyx::pos_type pos, bool boundary = false);
230 void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
231 bool setfont = true, bool boundary = false);
233 void setCurrentFont();
236 void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
238 void recUndo(lyx::paroffset_type first) const;
240 void setCursorFromCoordinates(int x, int y);
242 void setCursorFromCoordinates(LyXCursor &, int x, int y);
244 void cursorUp(bool selecting = false);
246 void cursorDown(bool selecting = false);
248 void cursorLeft(bool internal = true);
250 void cursorRight(bool internal = true);
252 void cursorLeftOneWord();
254 void cursorRightOneWord();
256 void cursorUpParagraph();
258 void cursorDownParagraph();
264 void cursorPrevious();
276 bool selectWordWhenUnderCursor(lyx::word_location);
282 text_capitalization = 1,
286 /// Change the case of the word at cursor position.
287 void changeCase(TextCase action);
292 void cutSelection(bool doclear = true, bool realcut = true);
294 void copySelection();
296 void pasteSelection(size_t sel_index = 0);
298 /** the DTP switches for paragraphs. LyX will store the top settings
299 always in the first physical paragraph, the bottom settings in the
300 last. When a paragraph is broken, the top settings rest, the bottom
301 settings are given to the new one. So I can make shure, they do not
302 duplicate themself (and you cannnot make dirty things with them! )
304 void setParagraph(bool line_top, bool line_bottom,
305 bool pagebreak_top, bool pagebreak_bottom,
306 VSpace const & space_top,
307 VSpace const & space_bottom,
308 Spacing const & spacing,
310 std::string const & labelwidthstring,
313 /* these things are for search and replace */
316 * Sets the selection from the current cursor position to length
317 * characters to the right. No safety checks.
319 void setSelectionRange(lyx::pos_type length);
321 /** simple replacing. The font of the first selected character
324 void replaceSelectionWithString(std::string const & str);
326 /// needed to insert the selection
327 void insertStringAsLines(std::string const & str);
328 /// needed to insert the selection
329 void insertStringAsParagraphs(std::string const & str);
331 /// Find next inset of some specified type.
332 bool gotoNextInset(std::vector<InsetOld::Code> const & codes,
333 std::string const & contents = std::string());
335 void gotoInset(std::vector<InsetOld::Code> const & codes,
338 void gotoInset(InsetOld::Code code, bool same_content);
341 int workWidth() const;
345 float getCursorX(ParagraphList::iterator pit,
346 Row const & row, lyx::pos_type pos, bool boundary) const;
347 /// used in setlayout
348 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
350 /// Calculate and set the height of the row
351 void setHeightOfRow(ParagraphList::iterator, Row & row);
353 // fix the cursor `cur' after a characters has been deleted at `where'
354 // position. Called by deleteEmptyParagraphMechanism
355 void fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where);
357 /// delete double space (false) or empty paragraphs (true) around old_cursor
358 bool deleteEmptyParagraphMechanism(LyXCursor const & old_cursor);
361 /** Updates all counters starting BEHIND the row. Changed paragraphs
362 * with a dynamic left margin will be rebroken. */
363 void updateCounters();
365 * Returns an inset if inset was hit, or 0 if not.
366 * If hit, the coordinates are changed relative to the inset.
368 InsetOld * checkInsetHit(int & x, int & y);
371 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
373 int singleWidth(ParagraphList::iterator pit,
374 lyx::pos_type pos, char c, LyXFont const & Font) const;
376 /// return the color of the canvas
377 LColor_color backgroundColor() const;
380 unsigned char transformChar(unsigned char c, Paragraph const & par,
381 lyx::pos_type pos) const;
384 * Returns the left beginning of the text.
385 * This information cannot be taken from the layout object, because
386 * in LaTeX the beginning of the text fits in some cases
387 * (for example sections) exactly the label-width.
389 int leftMargin(ParagraphList::iterator pit, Row const & row) const;
391 int rightMargin(Paragraph const & par, Buffer const &, Row const & row) const;
393 /** this calculates the specified parameters. needed when setting
394 * the cursor and when creating a visible row */
395 void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
399 void setCounter(Buffer const &, ParagraphList::iterator pit);
401 void deleteWordForward();
403 void deleteWordBackward();
405 void deleteLineForward();
407 /// sets row.end to the pos value *after* which a row should break.
408 /// for example, the pos after which isNewLine(pos) == true
409 void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
411 /// sets row.witdh to the minimum space a row needs on the screen in pixel
412 void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
415 * returns the minimum space a manual label needs on the
418 int labelFill(ParagraphList::iterator pit, Row const & row) const;
421 int labelEnd(ParagraphList::iterator pit, Row const & row) const;
432 ParagraphList * paragraphs_;
434 // special owner functions
436 ParagraphList & ownerParagraphs() const;
438 /// return true if this is owned by an inset.
439 bool isInInset() const;
441 /// return first row of text
442 RowList::iterator firstRow() const;
443 /// return last row of text
444 RowList::iterator lastRow() const;
445 /// return row "behind" last row of text
446 RowList::iterator endRow() const;
447 /// return next row crossing paragraph boundaries
448 void nextRow(ParagraphList::iterator & pit,
449 RowList::iterator & rit) const;
450 /// return previous row crossing paragraph boundaries
451 void previousRow(ParagraphList::iterator & pit,
452 RowList::iterator & rit) const;
454 /// is this row the last in the text?
455 bool isLastRow(ParagraphList::iterator pit, Row const & row) const;
456 /// is this row the first in the text?
457 bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
460 std::string selectionAsString(Buffer const & buffer, bool label) const;
462 /** Cursor related data.
463 Later this variable has to be removed. There should be now internal
466 ///TextCursor cursor_;
467 /// prohibit this as long as there are back pointers...
468 LyXText(LyXText const &);
471 /// return the default height of a row in pixels, considering font zoom
472 extern int defaultRowHeight();