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"
19 #include "dispatchresult.h"
20 #include "dimension.h"
23 #include "lyxlayout_ptr_fwd.h"
24 #include "ParagraphList.h"
51 /// This class encapsulates the main text data and operations in LyX
55 explicit LyXText(BufferView * bv = 0);
57 void init(BufferView *);
60 LyXFont getFont(Buffer const & buffer, Paragraph const & par,
63 void applyOuterFont(Buffer const & buffer, LyXFont &) const;
65 LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
67 LyXFont getLabelFont(Buffer const & buffer,
68 Paragraph const & par) const;
70 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
71 LyXFont const & font);
73 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
74 LyXFont const & font, bool toggleall);
76 /// what you expect when pressing <enter> at cursor position
77 void breakParagraph(LCursor & cur, bool keep_layout = false);
79 /// set layout over selection
80 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
81 std::string const & layout);
83 void setLayout(LCursor & cur, std::string const & layout);
85 /// what type of depth change to make
90 /// Increase or decrease the nesting depth of the selected paragraph(s)
91 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
93 /// Returns whether something would be changed by changeDepth
94 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
96 /// Set font over selection paragraphs and rebreak.
97 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
99 /// Rebreaks the given paragraph.
100 /// \retval true if a full screen redraw is needed.
101 /// \retval false if a single paragraph redraw is enough.
102 bool redoParagraph(BufferView &, pit_type pit);
104 /// returns pos in given par at given x coord
105 pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const;
106 int pos2x(pit_type pit, pos_type pos) const;
109 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
112 docstring getStringToIndex(LCursor const & cur);
114 /// insert a character at cursor position
115 void insertChar(LCursor & cur, char_type c);
116 /// insert an inset at cursor position
117 void insertInset(LCursor & cur, InsetBase * inset);
119 /// compute text metrics.
120 bool metrics(MetricsInfo & mi, Dimension & dim);
121 /// draw text (only used for insets)
122 void draw(PainterInfo & pi, int x, int y) const;
123 /// draw textselection
124 void drawSelection(PainterInfo & pi, int x, int y) const;
126 /// try to handle that request
127 void dispatch(LCursor & cur, FuncRequest & cmd);
128 /// do we want to handle this event?
129 bool getStatus(LCursor & cur, FuncRequest const & cmd,
130 FuncStatus & status) const;
132 /// read-only access to individual paragraph
133 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
134 /// read-write access to individual paragraph
135 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
136 // Returns the current font and depth as a message.
137 std::string currentState(LCursor & cur);
139 /** returns row near the specified
140 * y-coordinate in given paragraph (relative to the screen).
142 Row const & getRowNearY(BufferView const & bv, int y,
145 /// returns the paragraph number closest to screen y-coordinate.
146 /// This method uses the BufferView CoordCache to locate the
147 /// paragraph. The y-coodinate is allowed to be off-screen and
148 /// the CoordCache will be automatically updated if needed. This is
149 /// the reason why we need a non const BufferView and why this
150 /// method is non-const.
151 pit_type getPitNearY(BufferView & bv, int y);
153 /** returns the column near the specified x-coordinate of the row
154 x is set to the real beginning of this column
156 pos_type getColumnNearX(BufferView const & bv, pit_type pit,
157 Row const & row, int & x, bool & boundary) const;
159 /** Find the word under \c from in the relative location
160 * defined by \c word_location.
161 * @param from return here the start of the word
162 * @param to return here the end of the word
164 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
165 /// just selects the word the cursor is in
166 void selectWord(LCursor & cur, word_location loc);
168 /// accept selected change
169 void acceptChange(LCursor & cur);
170 /// reject selected change
171 void rejectChange(LCursor & cur);
173 /// returns true if par was empty and was removed
174 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
175 bool setfont = true, bool boundary = false);
177 void setCursor(CursorSlice &, pit_type par, pos_type pos);
179 void setCursorIntern(LCursor & cur, pit_type par,
180 pos_type pos, bool setfont = true, bool boundary = false);
182 void setCurrentFont(LCursor & cur);
185 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
187 void recUndo(LCursor & cur, pit_type first) const;
188 /// returns true if par was empty and was removed
189 bool setCursorFromCoordinates(LCursor & cur, int x, int y);
191 /// sets cursor recursively descending into nested editable insets
193 \return the inset pointer if x,y is covering that inset
194 \param x,y are absolute screen coordinates.
195 \retval inset is non-null if the cursor is positionned inside
197 InsetBase * editXY(LCursor & cur, int x, int y);
199 /// Move cursor one line up.
201 * Returns true if an update is needed after the move.
203 bool cursorUp(LCursor & cur);
204 /// Move cursor one line down.
206 * Returns true if an update is needed after the move.
208 bool cursorDown(LCursor & cur);
209 /// Move cursor one position left
211 * Returns true if an update is needed after the move.
213 bool cursorLeft(LCursor & cur);
214 /// Move cursor one position right
216 * Returns true if an update is needed after the move.
218 bool cursorRight(LCursor & cur);
220 bool cursorLeftOneWord(LCursor & cur);
222 bool cursorRightOneWord(LCursor & cur);
224 bool cursorUpParagraph(LCursor & cur);
226 bool cursorDownParagraph(LCursor & cur);
228 bool cursorHome(LCursor & cur);
230 bool cursorEnd(LCursor & cur);
232 void cursorPrevious(LCursor & cur);
234 void cursorNext(LCursor & cur);
236 bool cursorTop(LCursor & cur);
238 bool cursorBottom(LCursor & cur);
239 /// Erase character at cursor. Honour change tracking
240 bool erase(LCursor & cur);
241 /// Delete character before cursor. Honour CT
242 bool backspace(LCursor & cur);
243 // Dissolve the inset under cursor
244 bool dissolveInset(LCursor & cur);
246 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
252 text_capitalization = 1,
256 /// Change the case of the word at cursor position.
257 void changeCase(LCursor & cur, TextCase action);
258 /// Transposes the character at the cursor with the one before it
259 void charsTranspose(LCursor & cur);
261 /** the DTP switches for paragraphs. LyX will store the top settings
262 always in the first physical paragraph, the bottom settings in the
263 last. When a paragraph is broken, the top settings rest, the bottom
264 settings are given to the new one.
266 void setParagraph(LCursor & cur,
267 Spacing const & spacing,
269 docstring const & labelwidthstring,
272 /* these things are for search and replace */
274 /// needed to insert the selection
275 void insertStringAsLines(LCursor & cur, docstring const & str);
276 /// needed to insert the selection
277 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
279 /// current text width
282 /// current text heigth
285 /// Returns an inset if inset was hit, or 0 if not.
286 InsetBase * checkInsetHit(BufferView &, int x, int y);
289 int singleWidth(Buffer const &, Paragraph const & par,
292 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
293 LyXFont const & Font) const;
295 /// return the color of the canvas
296 LColor_color backgroundColor() const;
299 * Returns the left beginning of the text.
300 * This information cannot be taken from the layout object, because
301 * in LaTeX the beginning of the text fits in some cases
302 * (for example sections) exactly the label-width.
304 int leftMargin(Buffer const &, pit_type pit, pos_type pos) const;
305 int leftMargin(Buffer const &, pit_type pit) const;
307 int rightMargin(Buffer const &, Paragraph const & par) const;
309 /** this calculates the specified parameters. needed when setting
310 * the cursor and when creating a visible row */
311 RowMetrics computeRowMetrics(Buffer const &, pit_type pit,
312 Row const & row) const;
314 /// access to our paragraphs
315 ParagraphList const & paragraphs() const { return pars_; }
316 ParagraphList & paragraphs() { return pars_; }
317 /// return true if this is the main text
318 bool isMainText(Buffer const &) const;
320 /// return first row of text
321 Row const & firstRow() const;
323 /// is this row the last in the text?
324 bool isLastRow(pit_type pit, Row const & row) const;
325 /// is this row the first in the text?
326 bool isFirstRow(pit_type pit, Row const & row) const;
329 double spacing(Buffer const & buffer, Paragraph const & par) const;
330 /// make a suggestion for a label
331 docstring getPossibleLabel(LCursor & cur) const;
332 /// is this paragraph right-to-left?
333 bool isRTL(Buffer const &, Paragraph const & par) const;
335 bool checkAndActivateInset(LCursor & cur, bool front);
338 void write(Buffer const & buf, std::ostream & os) const;
339 /// returns whether we've seen our usual 'end' marker
340 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
347 int cursorX(Buffer const &, CursorSlice const & cursor,
348 bool boundary) const;
350 int cursorY(CursorSlice const & cursor, bool boundary) const;
352 /// delete double space or empty paragraphs around old cursor
353 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
360 /// the current font settings
361 LyXFont current_font;
363 LyXFont real_current_font;
365 int background_color_;
372 /// our 'outermost' font. This is handed down from the surrounding
373 // inset through the pi/mi parameter (pi.base.font)
379 /// return past-the-last paragraph influenced by a layout
381 pit_type undoSpan(pit_type pit);
383 /// Calculate and set the height of the row
384 void setHeightOfRow(BufferView const &, pit_type, Row & row);
386 // fix the cursor `cur' after a characters has been deleted at `where'
387 // position. Called by deleteEmptyParagraphMechanism
388 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
390 // At cursor position 0, try to merge the paragraph with the one before it.
391 // Ignore change tracking, i.e., physically remove the end-of-par character
392 bool backspacePos0(LCursor & cur);
395 void deleteWordForward(LCursor & cur);
397 void deleteWordBackward(LCursor & cur);
399 void deleteLineForward(LCursor & cur);
401 /// sets row.end to the pos value *after* which a row should break.
402 /// for example, the pos after which isNewLine(pos) == true
403 void rowBreakPoint(Buffer const &, int right_margin, pit_type pit,
405 /// sets row.width to the minimum space a row needs on the screen in pixel
406 void setRowWidth(Buffer const &, pit_type pit, Row & row) const;
407 /// the minimum space a manual label needs on the screen in pixels
408 int labelFill(Buffer const &, Paragraph const & par, Row const & row) const;
410 int labelEnd(Buffer const &, pit_type pit) const;
414 /// set 'number' font property
415 void number(LCursor & cur);
418 /// return the default height of a row in pixels, considering font zoom
419 int defaultRowHeight();