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;
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 /// FIXME: move to TextMetrics.
198 InsetBase * editXY(LCursor & cur, int x, int y);
200 /// Move cursor one line up.
202 * Returns true if an update is needed after the move.
204 /// FIXME: move to TextMetrics.
205 bool cursorUp(LCursor & cur);
206 /// Move cursor one line down.
208 * Returns true if an update is needed after the move.
210 /// FIXME: move to TextMetrics.
211 bool cursorDown(LCursor & cur);
212 /// Move cursor one position left
214 * Returns true if an update is needed after the move.
216 bool cursorLeft(LCursor & cur);
217 /// Move cursor one position right
219 * Returns true if an update is needed after the move.
221 bool cursorRight(LCursor & cur);
223 bool cursorLeftOneWord(LCursor & cur);
225 bool cursorRightOneWord(LCursor & cur);
227 bool cursorUpParagraph(LCursor & cur);
229 bool cursorDownParagraph(LCursor & cur);
231 /// FIXME: move to TextMetrics.
232 bool cursorHome(LCursor & cur);
234 /// FIXME: move to TextMetrics.
235 bool cursorEnd(LCursor & cur);
237 void cursorPrevious(LCursor & cur);
239 void cursorNext(LCursor & cur);
241 bool cursorTop(LCursor & cur);
243 bool cursorBottom(LCursor & cur);
244 /// Erase character at cursor. Honour change tracking
245 /// FIXME: replace LCursor with DocIterator.
246 bool erase(LCursor & cur);
247 /// Delete character before cursor. Honour CT
248 /// FIXME: replace LCursor with DocIterator.
249 bool backspace(LCursor & cur);
250 // Dissolve the inset under cursor
251 /// FIXME: replace LCursor with DocIterator.
252 bool dissolveInset(LCursor & cur);
254 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
260 text_capitalization = 1,
264 /// Change the case of the word at cursor position.
265 void changeCase(LCursor & cur, TextCase action);
266 /// Transposes the character at the cursor with the one before it
267 void charsTranspose(LCursor & cur);
269 /** the DTP switches for paragraphs. LyX will store the top settings
270 always in the first physical paragraph, the bottom settings in the
271 last. When a paragraph is broken, the top settings rest, the bottom
272 settings are given to the new one.
274 void setParagraph(LCursor & cur,
275 Spacing const & spacing,
277 docstring const & labelwidthstring,
280 /* these things are for search and replace */
282 /// needed to insert the selection
283 /// FIXME: replace LCursor with DocIterator.
284 void insertStringAsLines(LCursor & cur, docstring const & str);
285 /// needed to insert the selection
286 /// FIXME: replace LCursor with DocIterator.
287 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
289 /// Returns an inset if inset was hit, or 0 if not.
290 InsetBase * checkInsetHit(BufferView &, int x, int y);
293 /// FIXME: move to TextMetrics.
294 int singleWidth(Buffer const &, Paragraph const & par,
297 /// FIXME: move to TextMetrics.
298 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
299 LyXFont const & Font) const;
301 /// return the color of the canvas
302 LColor_color backgroundColor() const;
305 * Returns the left beginning of the text.
306 * This information cannot be taken from the layout object, because
307 * in LaTeX the beginning of the text fits in some cases
308 * (for example sections) exactly the label-width.
310 /// FIXME: move to TextMetrics.
311 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
312 int leftMargin(Buffer const &, int max_width, pit_type pit) 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 /// is this row the last in the text?
321 /// FIXME: move to TextMetrics.
322 bool isLastRow(pit_type pit, Row const & row) const;
323 /// is this row the first in the text?
324 /// FIXME: move to TextMetrics.
325 bool isFirstRow(pit_type pit, Row const & row) const;
328 double spacing(Buffer const & buffer, Paragraph const & par) const;
329 /// make a suggestion for a label
330 /// FIXME: replace LCursor with DocIterator.
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);
343 /// FIXME: move to TextMetrics.
344 int cursorX(BufferView const &, CursorSlice const & cursor,
345 bool boundary) const;
347 /// FIXME: move to TextMetrics.
348 int cursorY(BufferView const & bv, CursorSlice const & cursor,
349 bool boundary) const;
351 /// delete double space or empty paragraphs around old cursor
352 /// FIXME: replace LCursor with DocIterator. This is not possible right
353 /// now because recordUndo() is called which needs a LCursor.
354 bool deleteEmptyParagraphMechanism(LCursor & cur,
355 LCursor & old, bool & need_anchor_change);
357 /// sets row.end to the pos value *after* which a row should break.
358 /// for example, the pos after which isNewLine(pos) == true
359 /// FIXME: move to TextMetrics.
360 void rowBreakPoint(Buffer const &, int right_margin, int max_width, pit_type pit,
362 /// sets row.width to the minimum space a row needs on the screen in pixel
363 /// FIXME: move to TextMetrics.
364 void setRowWidth(Buffer const &, int right_margin, int max_width, pit_type pit,
367 /// Calculate and set the height of the row
368 /// FIXME: move to TextMetrics.
369 void setHeightOfRow(BufferView const &, pit_type, Row & row);
372 /// the current font settings
373 LyXFont current_font;
375 LyXFont real_current_font;
377 int background_color_;
384 /// our 'outermost' font. This is handed down from the surrounding
385 // inset through the pi/mi parameter (pi.base.font)
391 /// return past-the-last paragraph influenced by a layout
393 pit_type undoSpan(pit_type pit);
395 // fix the cursor `cur' after a characters has been deleted at `where'
396 // position. Called by deleteEmptyParagraphMechanism
397 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
399 // At cursor position 0, try to merge the paragraph with the one before it.
400 // Ignore change tracking, i.e., physically remove the end-of-par character
401 bool backspacePos0(LCursor & cur);
404 void deleteWordForward(LCursor & cur);
406 void deleteWordBackward(LCursor & cur);
408 void deleteLineForward(LCursor & cur);
411 int labelEnd(Buffer const &, int max_width, pit_type pit) const;
415 /// set 'number' font property
416 void number(LCursor & cur);