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 par
100 bool redoParagraph(BufferView &, pit_type pit);
102 /// returns pos in given par at given x coord
103 pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const;
104 int pos2x(pit_type pit, pos_type pos) const;
107 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
110 std::string getStringToIndex(LCursor const & cur);
112 /// insert a character at cursor position
113 void insertChar(LCursor & cur, char_type c);
114 /// insert an inset at cursor position
115 void insertInset(LCursor & cur, InsetBase * inset);
117 /// compute text metrics
118 void metrics(MetricsInfo & mi, Dimension & dim);
119 /// draw text (only used for insets)
120 void draw(PainterInfo & pi, int x, int y) const;
121 /// draw textselection
122 void drawSelection(PainterInfo & pi, int x, int y) const;
124 /// try to handle that request
125 void dispatch(LCursor & cur, FuncRequest & cmd);
126 /// do we want to handle this event?
127 bool getStatus(LCursor & cur, FuncRequest const & cmd,
128 FuncStatus & status) const;
130 /// read-only access to individual paragraph
131 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
132 /// read-write access to individual paragraph
133 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
134 // Returns the current font and depth as a message.
135 std::string currentState(LCursor & cur);
137 /** returns row near the specified
138 * y-coordinate in given paragraph (relative to the screen).
140 Row const & getRowNearY(BufferView const & bv, int y,
142 pit_type getPitNearY(BufferView const & bv, int y) const;
144 /** returns the column near the specified x-coordinate of the row
145 x is set to the real beginning of this column
147 pos_type getColumnNearX(BufferView const & bv, pit_type pit,
148 Row const & row, int & x, bool & boundary) const;
150 /** Find the word under \c from in the relative location
151 * defined by \c word_location.
152 * @param from return here the start of the word
153 * @param to return here the end of the word
155 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
156 /// just selects the word the cursor is in
157 void selectWord(LCursor & cur, word_location loc);
159 /// accept selected change
160 void acceptChange(LCursor & cur);
161 /// reject selected change
162 void rejectChange(LCursor & cur);
164 /// returns true if par was empty and was removed
165 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
166 bool setfont = true, bool boundary = false);
168 void setCursor(CursorSlice &, pit_type par, pos_type pos);
170 void setCursorIntern(LCursor & cur, pit_type par,
171 pos_type pos, bool setfont = true, bool boundary = false);
173 void setCurrentFont(LCursor & cur);
176 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
178 void recUndo(LCursor & cur, pit_type first) const;
179 /// returns true if par was empty and was removed
180 bool setCursorFromCoordinates(LCursor & cur, int x, int y);
182 InsetBase * editXY(LCursor & cur, int x, int y);
183 /// Move cursor one line up.
185 * Returns true if an update is needed after the move.
187 bool cursorUp(LCursor & cur);
188 /// Move cursor one line down.
190 * Returns true if an update is needed after the move.
192 bool cursorDown(LCursor & cur);
193 /// Move cursor one position left
195 * Returns true if an update is needed after the move.
197 bool cursorLeft(LCursor & cur);
198 /// Move cursor one position right
200 * Returns true if an update is needed after the move.
202 bool cursorRight(LCursor & cur);
204 bool cursorLeftOneWord(LCursor & cur);
206 bool cursorRightOneWord(LCursor & cur);
208 bool cursorUpParagraph(LCursor & cur);
210 bool cursorDownParagraph(LCursor & cur);
212 bool cursorHome(LCursor & cur);
214 bool cursorEnd(LCursor & cur);
216 bool cursorPrevious(LCursor & cur);
218 bool cursorNext(LCursor & cur);
220 bool cursorTop(LCursor & cur);
222 bool cursorBottom(LCursor & cur);
223 /// Erase character at cursor. Honour change tracking
224 bool erase(LCursor & cur);
225 /** At cursor position 0, merge paragraph with the one before it.
226 * Ignore CT (this is used in \c acceptChange, \c rejectChange for
227 * physical deletion of paragraph break)
229 bool backspacePos0(LCursor & cur);
230 /// Delete character before cursor. Honour CT
231 bool backspace(LCursor & cur);
232 // Dissolve the inset under cursor
233 bool dissolveInset(LCursor & cur);
235 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
241 text_capitalization = 1,
245 /// Change the case of the word at cursor position.
246 void changeCase(LCursor & cur, TextCase action);
248 /** the DTP switches for paragraphs. LyX will store the top settings
249 always in the first physical paragraph, the bottom settings in the
250 last. When a paragraph is broken, the top settings rest, the bottom
251 settings are given to the new one.
253 void setParagraph(LCursor & cur,
254 Spacing const & spacing,
256 std::string const & labelwidthstring,
259 /* these things are for search and replace */
261 /// needed to insert the selection
262 void insertStringAsLines(LCursor & cur, docstring const & str);
263 /// needed to insert the selection
264 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
266 /// current text width
269 /// current text heigth
272 /// Returns an inset if inset was hit, or 0 if not.
273 InsetBase * checkInsetHit(BufferView const &, int x, int y) const;
276 int singleWidth(Buffer const &, Paragraph const & par,
279 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
280 LyXFont const & Font) const;
282 /// return the color of the canvas
283 LColor_color backgroundColor() const;
286 * Returns the left beginning of the text.
287 * This information cannot be taken from the layout object, because
288 * in LaTeX the beginning of the text fits in some cases
289 * (for example sections) exactly the label-width.
291 int leftMargin(Buffer const &, pit_type pit, pos_type pos) const;
292 int leftMargin(Buffer const &, pit_type pit) const;
294 int rightMargin(Buffer const &, Paragraph const & par) const;
296 /** this calculates the specified parameters. needed when setting
297 * the cursor and when creating a visible row */
298 RowMetrics computeRowMetrics(Buffer const &, pit_type pit,
299 Row const & row) const;
301 /// access to our paragraphs
302 ParagraphList const & paragraphs() const { return pars_; }
303 ParagraphList & paragraphs() { return pars_; }
304 /// return true if this is the main text
305 bool isMainText(Buffer const &) const;
307 /// return first row of text
308 Row const & firstRow() const;
310 /// is this row the last in the text?
311 bool isLastRow(pit_type pit, Row const & row) const;
312 /// is this row the first in the text?
313 bool isFirstRow(pit_type pit, Row const & row) const;
316 double spacing(Buffer const & buffer, Paragraph const & par) const;
317 /// make a suggestion for a label
318 std::string getPossibleLabel(LCursor & cur) const;
319 /// is this paragraph right-to-left?
320 bool isRTL(Buffer const &, Paragraph const & par) const;
322 bool checkAndActivateInset(LCursor & cur, bool front);
325 void write(Buffer const & buf, std::ostream & os) const;
326 /// returns whether we've seen our usual 'end' marker
327 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
334 int cursorX(Buffer const &, CursorSlice const & cursor,
335 bool boundary) const;
337 int cursorY(CursorSlice const & cursor, bool boundary) const;
339 /// delete double space or empty paragraphs around old cursor
340 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
347 /// the current font settings
348 LyXFont current_font;
350 LyXFont real_current_font;
352 int background_color_;
359 /// our 'outermost' font. This is handed down from the surrounding
360 // inset through the pi/mi parameter (pi.base.font)
366 /// return past-the-last paragraph influenced by a layout
368 pit_type undoSpan(pit_type pit);
370 /// Calculate and set the height of the row
371 void setHeightOfRow(BufferView const &, pit_type, Row & row);
373 // fix the cursor `cur' after a characters has been deleted at `where'
374 // position. Called by deleteEmptyParagraphMechanism
375 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
378 void deleteWordForward(LCursor & cur);
380 void deleteWordBackward(LCursor & cur);
382 void deleteLineForward(LCursor & cur);
384 /// sets row.end to the pos value *after* which a row should break.
385 /// for example, the pos after which isNewLine(pos) == true
386 void rowBreakPoint(Buffer const &, pit_type pit, Row & row) const;
387 /// sets row.width to the minimum space a row needs on the screen in pixel
388 void setRowWidth(Buffer const &, pit_type pit, Row & row) const;
389 /// the minimum space a manual label needs on the screen in pixels
390 int labelFill(Buffer const &, Paragraph const & par, Row const & row) const;
392 int labelEnd(Buffer const &, pit_type pit) const;
396 /// set 'number' font property
397 void number(LCursor & cur);
400 /// return the default height of a row in pixels, considering font zoom
401 int defaultRowHeight();