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 "dispatchresult.h"
21 #include "lyxlayout_ptr_fwd.h"
22 #include "ParagraphList.h"
47 /// This class encapsulates the main text data and operations in LyX
54 LyXFont getFont(Buffer const & buffer, Paragraph const & par,
57 void applyOuterFont(Buffer const & buffer, LyXFont &) const;
59 LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
61 LyXFont getLabelFont(Buffer const & buffer,
62 Paragraph const & par) const;
64 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
65 LyXFont const & font);
67 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
68 LyXFont const & font, bool toggleall);
70 /// what you expect when pressing <enter> at cursor position
71 void breakParagraph(LCursor & cur, bool keep_layout = false);
73 /// set layout over selection
74 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
75 std::string const & layout);
76 /// Set given layout to current cursor position.
77 /// FIXME: replace LCursor with DocIterator.
78 void setLayout(LCursor & cur, std::string const & layout);
80 /// what type of depth change to make
85 /// Increase or decrease the nesting depth of the selected paragraph(s)
86 /// FIXME: replace LCursor with DocIterator.
87 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
89 /// Returns whether something would be changed by changeDepth
90 /// FIXME: replace LCursor with DocIterator.
91 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
93 /// Set font over selection paragraphs and rebreak.
94 /// FIXME: replace LCursor with DocIterator.
95 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
97 /// returns pos in given par at given x coord.
98 /// FIXME: move to TextMetrics.
99 pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const;
100 int pos2x(pit_type pit, pos_type pos) const;
103 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
106 /// FIXME: replace LCursor with DocIterator.
107 docstring getStringToIndex(LCursor const & cur);
109 /// insert a character at cursor position
110 /// FIXME: replace LCursor with DocIterator.
111 void insertChar(LCursor & cur, char_type c);
112 /// insert an inset at cursor position
113 /// FIXME: replace LCursor with DocIterator.
114 void insertInset(LCursor & cur, InsetBase * inset);
116 /// draw text (only used for insets)
117 void draw(PainterInfo & pi, int x, int y) const;
118 /// draw textselection
119 void drawSelection(PainterInfo & pi, int x, int y) const;
121 /// try to handle that request
122 /// FIXME: replace LCursor with DocIterator.
123 void dispatch(LCursor & cur, FuncRequest & cmd);
124 /// do we want to handle this event?
125 bool getStatus(LCursor & cur, FuncRequest const & cmd,
126 FuncStatus & status) const;
128 /// read-only access to individual paragraph
129 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
130 /// read-write access to individual paragraph
131 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
132 // Returns the current font and depth as a message.
133 /// FIXME: replace LCursor with DocIterator.
134 docstring currentState(LCursor & cur);
136 /** returns row near the specified
137 * y-coordinate in given paragraph (relative to the screen).
139 /// FIXME: move to TextMetrics.
140 Row const & getRowNearY(BufferView const & bv, int y,
143 /// returns the paragraph number closest to screen y-coordinate.
144 /// This method uses the BufferView CoordCache to locate the
145 /// paragraph. The y-coodinate is allowed to be off-screen and
146 /// the CoordCache will be automatically updated if needed. This is
147 /// the reason why we need a non const BufferView and why this
148 /// method is non-const.
149 /// FIXME: move to TextMetrics.
150 pit_type getPitNearY(BufferView & bv, int y);
152 /** returns the column near the specified x-coordinate of the row
153 x is set to the real beginning of this column
155 /// FIXME: move to TextMetrics.
156 pos_type getColumnNearX(BufferView const & bv, int right_margin,
157 pit_type pit, 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;
189 /// sets cursor only within this LyXText.
190 /// x,y are screen coordinates
191 void setCursorFromCoordinates(LCursor & cur, int x, int y);
193 /// sets cursor recursively descending into nested editable insets
195 \return the inset pointer if x,y is covering that inset
196 \param x,y are absolute screen coordinates.
197 \retval inset is non-null if the cursor is positionned inside
199 /// FIXME: move to TextMetrics.
200 InsetBase * editXY(LCursor & cur, int x, int y);
202 /// Move cursor one line up.
204 * Returns true if an update is needed after the move.
206 /// FIXME: move to TextMetrics.
207 bool cursorUp(LCursor & cur);
208 /// Move cursor one line down.
210 * Returns true if an update is needed after the move.
212 /// FIXME: move to TextMetrics.
213 bool cursorDown(LCursor & cur);
214 /// Move cursor one position left
216 * Returns true if an update is needed after the move.
218 bool cursorLeft(LCursor & cur);
219 /// Move cursor one position right
221 * Returns true if an update is needed after the move.
223 bool cursorRight(LCursor & cur);
225 bool cursorLeftOneWord(LCursor & cur);
227 bool cursorRightOneWord(LCursor & cur);
229 bool cursorUpParagraph(LCursor & cur);
231 bool cursorDownParagraph(LCursor & cur);
233 /// FIXME: move to TextMetrics.
234 bool cursorHome(LCursor & cur);
236 /// FIXME: move to TextMetrics.
237 bool cursorEnd(LCursor & cur);
239 void cursorPrevious(LCursor & cur);
241 void cursorNext(LCursor & cur);
243 bool cursorTop(LCursor & cur);
245 bool cursorBottom(LCursor & cur);
246 /// Erase character at cursor. Honour change tracking
247 /// FIXME: replace LCursor with DocIterator.
248 bool erase(LCursor & cur);
249 /// Delete character before cursor. Honour CT
250 /// FIXME: replace LCursor with DocIterator.
251 bool backspace(LCursor & cur);
252 // Dissolve the inset under cursor
253 /// FIXME: replace LCursor with DocIterator.
254 bool dissolveInset(LCursor & cur);
256 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
262 text_capitalization = 1,
266 /// Change the case of the word at cursor position.
267 void changeCase(LCursor & cur, TextCase action);
268 /// Transposes the character at the cursor with the one before it
269 void charsTranspose(LCursor & cur);
271 /** the DTP switches for paragraphs. LyX will store the top settings
272 always in the first physical paragraph, the bottom settings in the
273 last. When a paragraph is broken, the top settings rest, the bottom
274 settings are given to the new one.
276 void setParagraph(LCursor & cur,
277 Spacing const & spacing,
279 docstring const & labelwidthstring,
282 /* these things are for search and replace */
284 /// needed to insert the selection
285 /// FIXME: replace LCursor with DocIterator.
286 void insertStringAsLines(LCursor & cur, docstring const & str);
287 /// needed to insert the selection
288 /// FIXME: replace LCursor with DocIterator.
289 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
291 /// Returns an inset if inset was hit, or 0 if not.
292 InsetBase * checkInsetHit(BufferView &, int x, int y);
295 /// FIXME: move to TextMetrics.
296 int singleWidth(Buffer const &, Paragraph const & par,
299 /// FIXME: move to TextMetrics.
300 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
301 LyXFont const & Font) const;
303 /// return the color of the canvas
304 LColor_color backgroundColor() const;
307 * Returns the left beginning of the text.
308 * This information cannot be taken from the layout object, because
309 * in LaTeX the beginning of the text fits in some cases
310 * (for example sections) exactly the label-width.
312 /// FIXME: move to TextMetrics.
313 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
314 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
316 /// access to our paragraphs
317 ParagraphList const & paragraphs() const { return pars_; }
318 ParagraphList & paragraphs() { return pars_; }
319 /// return true if this is the main text
320 bool isMainText(Buffer const &) const;
322 /// is this row the last in the text?
323 /// FIXME: move to TextMetrics.
324 bool isLastRow(pit_type pit, Row const & row) const;
325 /// is this row the first in the text?
326 /// FIXME: move to TextMetrics.
327 bool isFirstRow(pit_type pit, Row const & row) const;
330 double spacing(Buffer const & buffer, Paragraph const & par) const;
331 /// make a suggestion for a label
332 /// FIXME: replace LCursor with DocIterator.
333 docstring getPossibleLabel(LCursor & cur) const;
334 /// is this paragraph right-to-left?
335 bool isRTL(Buffer const &, Paragraph const & par) const;
337 bool checkAndActivateInset(LCursor & cur, bool front);
340 void write(Buffer const & buf, std::ostream & os) const;
341 /// returns whether we've seen our usual 'end' marker
342 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
345 /// FIXME: move to TextMetrics.
346 int cursorX(BufferView const &, CursorSlice const & cursor,
347 bool boundary) const;
349 /// FIXME: move to TextMetrics.
350 int cursorY(BufferView const & bv, CursorSlice const & cursor,
351 bool boundary) const;
353 /// delete double space or empty paragraphs around old cursor
354 /// FIXME: replace LCursor with DocIterator. This is not possible right
355 /// now because recordUndo() is called which needs a LCursor.
356 bool deleteEmptyParagraphMechanism(LCursor & cur,
357 LCursor & old, bool & need_anchor_change);
359 /// sets row.end to the pos value *after* which a row should break.
360 /// for example, the pos after which isNewLine(pos) == true
361 /// FIXME: move to TextMetrics.
362 void rowBreakPoint(Buffer const &, int right_margin, int max_width, pit_type pit,
364 /// sets row.width to the minimum space a row needs on the screen in pixel
365 /// FIXME: move to TextMetrics.
366 void setRowWidth(Buffer const &, int right_margin, int max_width, pit_type pit,
369 /// Calculate and set the height of the row
370 /// FIXME: move to TextMetrics.
371 void setHeightOfRow(BufferView const &, pit_type, Row & row);
374 /// the current font settings
375 LyXFont current_font;
377 LyXFont real_current_font;
379 int background_color_;
386 /// our 'outermost' font. This is handed down from the surrounding
387 // inset through the pi/mi parameter (pi.base.font)
393 /// return past-the-last paragraph influenced by a layout
395 pit_type undoSpan(pit_type pit);
397 // fix the cursor `cur' after a characters has been deleted at `where'
398 // position. Called by deleteEmptyParagraphMechanism
399 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
401 // At cursor position 0, try to merge the paragraph with the one before it.
402 // Ignore change tracking, i.e., physically remove the end-of-par character
403 bool backspacePos0(LCursor & cur);
406 void deleteWordForward(LCursor & cur);
408 void deleteWordBackward(LCursor & cur);
410 void deleteLineForward(LCursor & cur);
413 int labelEnd(Buffer const &, int max_width, pit_type pit) const;
417 /// set 'number' font property
418 void number(LCursor & cur);