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 /** Find the word under \c from in the relative location
153 * defined by \c word_location.
154 * @param from return here the start of the word
155 * @param to return here the end of the word
157 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
158 /// just selects the word the cursor is in
159 void selectWord(LCursor & cur, word_location loc);
161 /// accept selected change
162 void acceptChange(LCursor & cur);
163 /// reject selected change
164 void rejectChange(LCursor & cur);
166 /// returns true if par was empty and was removed
167 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
168 bool setfont = true, bool boundary = false);
170 void setCursor(CursorSlice &, pit_type par, pos_type pos);
172 void setCursorIntern(LCursor & cur, pit_type par,
173 pos_type pos, bool setfont = true, bool boundary = false);
175 void setCurrentFont(LCursor & cur);
178 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
180 void recUndo(LCursor & cur, pit_type first) const;
182 /// sets cursor only within this LyXText.
183 /// x,y are screen coordinates
184 void setCursorFromCoordinates(LCursor & cur, int x, int y);
186 /// sets cursor recursively descending into nested editable insets
188 \return the inset pointer if x,y is covering that inset
189 \param x,y are absolute screen coordinates.
190 \retval inset is non-null if the cursor is positionned inside
192 /// FIXME: move to TextMetrics.
193 InsetBase * editXY(LCursor & cur, int x, int y);
195 /// Move cursor one line up.
197 * Returns true if an update is needed after the move.
199 /// FIXME: move to TextMetrics.
200 bool cursorUp(LCursor & cur);
201 /// Move cursor one line down.
203 * Returns true if an update is needed after the move.
205 /// FIXME: move to TextMetrics.
206 bool cursorDown(LCursor & cur);
207 /// Move cursor one position left
209 * Returns true if an update is needed after the move.
211 bool cursorLeft(LCursor & cur);
212 /// Move cursor one position right
214 * Returns true if an update is needed after the move.
216 bool cursorRight(LCursor & cur);
218 bool cursorLeftOneWord(LCursor & cur);
220 bool cursorRightOneWord(LCursor & cur);
222 bool cursorUpParagraph(LCursor & cur);
224 bool cursorDownParagraph(LCursor & cur);
226 /// FIXME: move to TextMetrics.
227 bool cursorHome(LCursor & cur);
229 /// FIXME: move to TextMetrics.
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 /// FIXME: replace LCursor with DocIterator.
241 bool erase(LCursor & cur);
242 /// Delete character before cursor. Honour CT
243 /// FIXME: replace LCursor with DocIterator.
244 bool backspace(LCursor & cur);
245 // Dissolve the inset under cursor
246 /// FIXME: replace LCursor with DocIterator.
247 bool dissolveInset(LCursor & cur);
249 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
255 text_capitalization = 1,
259 /// Change the case of the word at cursor position.
260 void changeCase(LCursor & cur, TextCase action);
261 /// Transposes the character at the cursor with the one before it
262 void charsTranspose(LCursor & cur);
264 /** the DTP switches for paragraphs. LyX will store the top settings
265 always in the first physical paragraph, the bottom settings in the
266 last. When a paragraph is broken, the top settings rest, the bottom
267 settings are given to the new one.
269 void setParagraph(LCursor & cur,
270 Spacing const & spacing,
272 docstring const & labelwidthstring,
275 /* these things are for search and replace */
277 /// needed to insert the selection
278 /// FIXME: replace LCursor with DocIterator.
279 void insertStringAsLines(LCursor & cur, docstring const & str);
280 /// needed to insert the selection
281 /// FIXME: replace LCursor with DocIterator.
282 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
284 /// Returns an inset if inset was hit, or 0 if not.
285 InsetBase * checkInsetHit(BufferView &, int x, int y);
288 /// FIXME: move to TextMetrics.
289 int singleWidth(Buffer const &, Paragraph const & par,
292 /// FIXME: move to TextMetrics.
293 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
294 LyXFont const & Font) const;
296 /// return the color of the canvas
297 LColor_color backgroundColor() const;
300 * Returns the left beginning of the text.
301 * This information cannot be taken from the layout object, because
302 * in LaTeX the beginning of the text fits in some cases
303 * (for example sections) exactly the label-width.
305 /// FIXME: move to TextMetrics.
306 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
307 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
309 /// access to our paragraphs
310 ParagraphList const & paragraphs() const { return pars_; }
311 ParagraphList & paragraphs() { return pars_; }
312 /// return true if this is the main text
313 bool isMainText(Buffer const &) const;
315 /// is this row the last in the text?
316 /// FIXME: move to TextMetrics.
317 bool isLastRow(pit_type pit, Row const & row) const;
318 /// is this row the first in the text?
319 /// FIXME: move to TextMetrics.
320 bool isFirstRow(pit_type pit, Row const & row) const;
323 double spacing(Buffer const & buffer, Paragraph const & par) const;
324 /// make a suggestion for a label
325 /// FIXME: replace LCursor with DocIterator.
326 docstring getPossibleLabel(LCursor & cur) const;
327 /// is this paragraph right-to-left?
328 bool isRTL(Buffer const &, Paragraph const & par) const;
330 bool checkAndActivateInset(LCursor & cur, bool front);
333 void write(Buffer const & buf, std::ostream & os) const;
334 /// returns whether we've seen our usual 'end' marker
335 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
338 /// FIXME: move to TextMetrics.
339 int cursorX(BufferView const &, CursorSlice const & cursor,
340 bool boundary) const;
342 /// FIXME: move to TextMetrics.
343 int cursorY(BufferView const & bv, CursorSlice const & cursor,
344 bool boundary) const;
346 /// delete double space or empty paragraphs around old cursor
347 /// FIXME: replace LCursor with DocIterator. This is not possible right
348 /// now because recordUndo() is called which needs a LCursor.
349 bool deleteEmptyParagraphMechanism(LCursor & cur,
350 LCursor & old, bool & need_anchor_change);
353 /// the current font settings
354 LyXFont current_font;
356 LyXFont real_current_font;
358 int background_color_;
365 /// our 'outermost' font. This is handed down from the surrounding
366 // inset through the pi/mi parameter (pi.base.font)
372 /// return past-the-last paragraph influenced by a layout
374 pit_type undoSpan(pit_type pit);
376 // fix the cursor `cur' after a characters has been deleted at `where'
377 // position. Called by deleteEmptyParagraphMechanism
378 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
380 // At cursor position 0, try to merge the paragraph with the one before it.
381 // Ignore change tracking, i.e., physically remove the end-of-par character
382 bool backspacePos0(LCursor & cur);
385 void deleteWordForward(LCursor & cur);
387 void deleteWordBackward(LCursor & cur);
389 void deleteLineForward(LCursor & cur);
392 /// set 'number' font property
393 void number(LCursor & cur);