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);
98 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
101 /// FIXME: replace LCursor with DocIterator.
102 docstring getStringToIndex(LCursor const & cur);
104 /// insert a character at cursor position
105 /// FIXME: replace LCursor with DocIterator.
106 void insertChar(LCursor & cur, char_type c);
107 /// insert an inset at cursor position
108 /// FIXME: replace LCursor with DocIterator.
109 void insertInset(LCursor & cur, InsetBase * inset);
111 /// draw text (only used for insets)
112 void draw(PainterInfo & pi, int x, int y) const;
113 /// draw textselection
114 void drawSelection(PainterInfo & pi, int x, int y) const;
116 /// try to handle that request
117 /// FIXME: replace LCursor with DocIterator.
118 void dispatch(LCursor & cur, FuncRequest & cmd);
119 /// do we want to handle this event?
120 bool getStatus(LCursor & cur, FuncRequest const & cmd,
121 FuncStatus & status) const;
123 /// read-only access to individual paragraph
124 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
125 /// read-write access to individual paragraph
126 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
127 // Returns the current font and depth as a message.
128 /// FIXME: replace LCursor with DocIterator.
129 docstring currentState(LCursor & cur);
131 /** returns row near the specified
132 * y-coordinate in given paragraph (relative to the screen).
134 /// FIXME: move to TextMetrics.
135 Row const & getRowNearY(BufferView const & bv, int y,
138 /// returns the paragraph number closest to screen y-coordinate.
139 /// This method uses the BufferView CoordCache to locate the
140 /// paragraph. The y-coodinate is allowed to be off-screen and
141 /// the CoordCache will be automatically updated if needed. This is
142 /// the reason why we need a non const BufferView and why this
143 /// method is non-const.
144 /// FIXME: move to TextMetrics.
145 pit_type getPitNearY(BufferView & bv, int y);
147 /** Find the word under \c from in the relative location
148 * defined by \c word_location.
149 * @param from return here the start of the word
150 * @param to return here the end of the word
152 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
153 /// just selects the word the cursor is in
154 void selectWord(LCursor & cur, word_location loc);
156 /// accept selected change
157 void acceptChange(LCursor & cur);
158 /// reject selected change
159 void rejectChange(LCursor & cur);
161 /// returns true if par was empty and was removed
162 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
163 bool setfont = true, bool boundary = false);
165 void setCursor(CursorSlice &, pit_type par, pos_type pos);
167 void setCursorIntern(LCursor & cur, pit_type par,
168 pos_type pos, bool setfont = true, bool boundary = false);
170 void setCurrentFont(LCursor & cur);
173 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
175 void recUndo(LCursor & cur, pit_type first) const;
177 /// sets cursor only within this LyXText.
178 /// x,y are screen coordinates
179 void setCursorFromCoordinates(LCursor & cur, int x, int y);
181 /// sets cursor recursively descending into nested editable insets
183 \return the inset pointer if x,y is covering that inset
184 \param x,y are absolute screen coordinates.
185 \retval inset is non-null if the cursor is positionned inside
187 /// FIXME: move to TextMetrics.
188 InsetBase * editXY(LCursor & cur, int x, int y);
190 /// Move cursor one line up.
192 * Returns true if an update is needed after the move.
194 /// FIXME: move to TextMetrics.
195 bool cursorUp(LCursor & cur);
196 /// Move cursor one line down.
198 * Returns true if an update is needed after the move.
200 /// FIXME: move to TextMetrics.
201 bool cursorDown(LCursor & cur);
202 /// Move cursor one position left
204 * Returns true if an update is needed after the move.
206 bool cursorLeft(LCursor & cur);
207 /// Move cursor one position right
209 * Returns true if an update is needed after the move.
211 bool cursorRight(LCursor & cur);
213 bool cursorLeftOneWord(LCursor & cur);
215 bool cursorRightOneWord(LCursor & cur);
217 bool cursorUpParagraph(LCursor & cur);
219 bool cursorDownParagraph(LCursor & cur);
221 /// FIXME: move to TextMetrics.
222 bool cursorHome(LCursor & cur);
224 /// FIXME: move to TextMetrics.
225 bool cursorEnd(LCursor & cur);
227 void cursorPrevious(LCursor & cur);
229 void cursorNext(LCursor & cur);
231 bool cursorTop(LCursor & cur);
233 bool cursorBottom(LCursor & cur);
234 /// Erase character at cursor. Honour change tracking
235 /// FIXME: replace LCursor with DocIterator.
236 bool erase(LCursor & cur);
237 /// Delete character before cursor. Honour CT
238 /// FIXME: replace LCursor with DocIterator.
239 bool backspace(LCursor & cur);
240 // Dissolve the inset under cursor
241 /// FIXME: replace LCursor with DocIterator.
242 bool dissolveInset(LCursor & cur);
244 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
250 text_capitalization = 1,
254 /// Change the case of the word at cursor position.
255 void changeCase(LCursor & cur, TextCase action);
256 /// Transposes the character at the cursor with the one before it
257 void charsTranspose(LCursor & cur);
259 /** the DTP switches for paragraphs. LyX will store the top settings
260 always in the first physical paragraph, the bottom settings in the
261 last. When a paragraph is broken, the top settings rest, the bottom
262 settings are given to the new one.
264 void setParagraph(LCursor & cur,
265 Spacing const & spacing,
267 docstring const & labelwidthstring,
270 /* these things are for search and replace */
272 /// needed to insert the selection
273 /// FIXME: replace LCursor with DocIterator.
274 void insertStringAsLines(LCursor & cur, docstring const & str);
275 /// needed to insert the selection
276 /// FIXME: replace LCursor with DocIterator.
277 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
279 /// Returns an inset if inset was hit, or 0 if not.
280 InsetBase * checkInsetHit(BufferView &, int x, int y);
283 /// FIXME: move to TextMetrics.
284 int singleWidth(Buffer const &, Paragraph const & par,
287 /// FIXME: move to TextMetrics.
288 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
289 LyXFont const & Font) const;
291 /// return the color of the canvas
292 LColor_color backgroundColor() const;
295 * Returns the left beginning of the text.
296 * This information cannot be taken from the layout object, because
297 * in LaTeX the beginning of the text fits in some cases
298 * (for example sections) exactly the label-width.
300 /// FIXME: move to TextMetrics.
301 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
302 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
304 /// access to our paragraphs
305 ParagraphList const & paragraphs() const { return pars_; }
306 ParagraphList & paragraphs() { return pars_; }
307 /// return true if this is the main text
308 bool isMainText(Buffer const &) const;
310 /// is this row the last in the text?
311 /// FIXME: move to TextMetrics.
312 bool isLastRow(pit_type pit, Row const & row) const;
313 /// is this row the first in the text?
314 /// FIXME: move to TextMetrics.
315 bool isFirstRow(pit_type pit, Row const & row) const;
318 double spacing(Buffer const & buffer, Paragraph const & par) const;
319 /// make a suggestion for a label
320 /// FIXME: replace LCursor with DocIterator.
321 docstring getPossibleLabel(LCursor & cur) const;
322 /// is this paragraph right-to-left?
323 bool isRTL(Buffer const &, Paragraph const & par) const;
325 bool checkAndActivateInset(LCursor & cur, bool front);
328 void write(Buffer const & buf, std::ostream & os) const;
329 /// returns whether we've seen our usual 'end' marker
330 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
333 /// FIXME: move to TextMetrics.
334 int cursorX(BufferView const &, CursorSlice const & cursor,
335 bool boundary) const;
337 /// FIXME: move to TextMetrics.
338 int cursorY(BufferView const & bv, CursorSlice const & cursor,
339 bool boundary) const;
341 /// delete double space or empty paragraphs around old cursor
342 /// FIXME: replace LCursor with DocIterator. This is not possible right
343 /// now because recordUndo() is called which needs a LCursor.
344 bool deleteEmptyParagraphMechanism(LCursor & cur,
345 LCursor & old, bool & need_anchor_change);
348 /// the current font settings
349 LyXFont current_font;
351 LyXFont real_current_font;
353 int background_color_;
360 /// our 'outermost' font. This is handed down from the surrounding
361 // inset through the pi/mi parameter (pi.base.font)
367 /// return past-the-last paragraph influenced by a layout
369 pit_type undoSpan(pit_type pit);
371 // fix the cursor `cur' after a characters has been deleted at `where'
372 // position. Called by deleteEmptyParagraphMechanism
373 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
375 // At cursor position 0, try to merge the paragraph with the one before it.
376 // Ignore change tracking, i.e., physically remove the end-of-par character
377 bool backspacePos0(LCursor & cur);
380 void deleteWordForward(LCursor & cur);
382 void deleteWordBackward(LCursor & cur);
384 void deleteLineForward(LCursor & cur);
387 /// set 'number' font property
388 void number(LCursor & cur);
390 /// paste plain text at current cursor.
391 /// \param str string to paste
392 /// \param asParagraphs whether to paste as paragraphs or as lines
393 void pasteString(LCursor & cur, docstring const & str,