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"
22 #include "lyxlayout_ptr_fwd.h"
23 #include "RowList_fwd.h"
24 #include "ParagraphList_fwd.h"
47 /// This class encapsulates the main text data and operations in LyX
51 typedef lyx::pos_type pos_type;
53 typedef lyx::par_type par_type;
56 explicit LyXText(BufferView *);
58 void init(BufferView *);
60 /// update y coordinate cache of all paragraphs
61 void updateParPositions();
63 LyXFont getFont(par_type pit, pos_type pos) const;
65 LyXFont getLayoutFont(par_type pit) const;
67 LyXFont getLabelFont(par_type pit) const;
69 void setCharFont(par_type pit, pos_type pos, LyXFont const & font);
71 void setCharFont(par_type pit, pos_type pos, LyXFont const & font,
74 /// what you expect when pressing <enter> at cursor position
75 void breakParagraph(LCursor & cur, char keep_layout = 0);
77 /// set layout over selection
78 par_type setLayout(par_type start, par_type end,
79 std::string const & layout);
81 void setLayout(LCursor & cur, std::string const & layout);
83 /// what type of depth change to make
88 /// Increase or decrease the nesting depth of the selected paragraph(s)
89 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
91 /// Returns whether something would be changed by changeDepth
92 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
94 /// Set font over selection paragraphs and rebreak.
95 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
97 /// rebreaks all paragaphs between the given pars.
98 void redoParagraphs(par_type begin, par_type end);
99 /// rebreaks the given par
100 void redoParagraph(par_type pit);
101 /// rebreaks the cursor par
102 void redoParagraph(LCursor & cur);
105 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
108 std::string getStringToIndex(LCursor & cur);
110 /// insert a character at cursor position
111 void insertChar(LCursor & cur, char c);
112 /// insert an inset at cursor position
113 void insertInset(LCursor & cur, InsetBase * inset);
115 /// a full rebreak of the whole text
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;
123 /// returns distance of this cell to the point given by x and y
124 // assumes valid position and size cache
125 int dist(int x, int y) const;
127 /// try to handle that request
128 void dispatch(LCursor & cur, FuncRequest & cmd);
129 /// do we want to handle this event?
130 bool getStatus(LCursor & cur, FuncRequest const & cmd,
131 FuncStatus & status) const;
133 /// access to out BufferView. This should go...
135 /// access to out BufferView. This should go...
136 BufferView * bv() const;
138 /// access to individual paragraphs
139 Paragraph & getPar(par_type par) const;
140 // Returns the current font and depth as a message.
141 std::string LyXText::currentState(LCursor & cur);
143 /** returns an iterator pointing to the row near the specified
144 * y-coordinate (relative to the whole text). y is set to the
145 * real beginning of this row
147 RowList::iterator getRowNearY(int y, par_type & pit) const;
149 /** returns the column near the specified x-coordinate of the row
150 x is set to the real beginning of this column
152 pos_type getColumnNearX(par_type pit,
153 Row const & row, int & x, bool & boundary) const;
155 /** Find the word under \c from in the relative location
156 * defined by \c word_location.
157 * @param from return here the start of the word
158 * @param to return here the end of the word
160 void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
161 /// just selects the word the cursor is in
162 void selectWord(LCursor & cur, lyx::word_location loc);
164 /// accept selected change
165 void acceptChange(LCursor & cur);
166 /// reject selected change
167 void rejectChange(LCursor & cur);
169 /// returns true if par was empty and was removed
170 bool setCursor(LCursor & cur, par_type par, pos_type pos,
171 bool setfont = true, bool boundary = false);
173 void setCursor(CursorSlice &, par_type par,
174 pos_type pos, bool boundary = false);
176 void setCursorIntern(LCursor & cur, par_type par,
177 pos_type pos, bool setfont = true, bool boundary = false);
179 void setCurrentFont(LCursor & cur);
182 void recUndo(par_type first, par_type last) const;
184 void recUndo(par_type first) const;
186 void setCursorFromCoordinates(LCursor & cur, int x, int y);
188 InsetBase * editXY(LCursor & cur, int x, int y);
190 void cursorUp(LCursor & cur);
192 void cursorDown(LCursor & cur);
194 void cursorLeft(LCursor & cur);
196 void cursorRight(LCursor & cur);
198 void cursorLeftOneWord(LCursor & cur);
200 void cursorRightOneWord(LCursor & cur);
202 void cursorUpParagraph(LCursor & cur);
204 void cursorDownParagraph(LCursor & cur);
206 void cursorHome(LCursor & cur);
208 void cursorEnd(LCursor & cur);
210 void cursorPrevious(LCursor & cur);
212 void cursorNext(LCursor & cur);
214 void cursorTop(LCursor & cur);
216 void cursorBottom(LCursor & cur);
218 void Delete(LCursor & cur);
220 void backspace(LCursor & cur);
222 bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
228 text_capitalization = 1,
232 /// Change the case of the word at cursor position.
233 void changeCase(LCursor & cur, TextCase action);
235 /** the DTP switches for paragraphs. LyX will store the top settings
236 always in the first physical paragraph, the bottom settings in the
237 last. When a paragraph is broken, the top settings rest, the bottom
238 settings are given to the new one.
240 void setParagraph(LCursor & cur,
241 Spacing const & spacing,
243 std::string const & labelwidthstring,
246 /* these things are for search and replace */
248 /// needed to insert the selection
249 void insertStringAsLines(LCursor & cur, std::string const & str);
250 /// needed to insert the selection
251 void insertStringAsParagraphs(LCursor & cur, std::string const & str);
253 /// Find next inset of some specified type.
254 bool gotoNextInset(LCursor & cur,
255 std::vector<InsetOld_code> const & codes,
256 std::string const & contents = std::string());
258 void gotoInset(LCursor & cur,
259 std::vector<InsetOld_code> const & codes, bool same_content);
261 void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
263 /// current text width
266 /// current text heigth
269 /// updates all counters
270 void updateCounters();
271 /// Returns an inset if inset was hit, or 0 if not.
272 InsetBase * checkInsetHit(int x, int y);
275 int singleWidth(par_type pit, pos_type pos) const;
277 int singleWidth(par_type pit,
278 pos_type pos, char c, LyXFont const & Font) const;
280 /// return the color of the canvas
281 LColor_color backgroundColor() const;
284 * Returns the left beginning of the text.
285 * This information cannot be taken from the layout object, because
286 * in LaTeX the beginning of the text fits in some cases
287 * (for example sections) exactly the label-width.
289 int leftMargin(par_type pit, pos_type pos) const;
290 int leftMargin(par_type pit) const;
292 int rightMargin(Paragraph const & par) const;
294 /** this calculates the specified parameters. needed when setting
295 * the cursor and when creating a visible row */
296 RowMetrics computeRowMetrics(par_type pit, Row const & row) const;
298 /// access to our paragraphs
299 ParagraphList & paragraphs() const;
300 /// return true if this is the main text
301 bool isMainText() const;
303 /// return first row of text
304 RowList::iterator firstRow() const;
305 /// return last row of text
306 RowList::iterator lastRow() const;
307 /// return row "behind" last row of text
308 RowList::iterator endRow() const;
309 /// return next row crossing paragraph boundaries
310 void nextRow(par_type & pit, RowList::iterator & rit) const;
311 /// return previous row crossing paragraph boundaries
312 void previousRow(par_type & pit, RowList::iterator & rit) const;
314 /// is this row the last in the text?
315 bool isLastRow(par_type pit, Row const & row) const;
316 /// is this row the first in the text?
317 bool isFirstRow(par_type pit, Row const & row) const;
320 double spacing(Paragraph const & par) const;
321 /// make a suggestion for a label
322 std::string getPossibleLabel(LCursor & cur) const;
323 /// is this paragraph right-to-left?
324 bool isRTL(Paragraph const & par) const;
326 bool checkAndActivateInset(LCursor & cur, bool front);
329 void write(Buffer const & buf, std::ostream & os) const;
330 /// returns whether we've seen our usual 'end' marker
331 bool read(Buffer const & buf, LyXLex & lex);
338 int cursorX(CursorSlice const & cursor) const;
340 int cursorY(CursorSlice const & cursor) const;
343 friend class LyXScreen;
352 /// the current font settings
353 LyXFont current_font;
355 LyXFont real_current_font;
356 /// our buffer's default layout font
357 LyXFont defaultfont_;
359 int background_color_;
361 /// only the top-level LyXText has this non-zero
362 BufferView * bv_owner;
369 /// absolute document pixel coordinates of this LyXText
373 /// our 'outermost' Font
377 /// return past-the-last paragraph influenced by a layout
379 par_type undoSpan(par_type pit);
381 /// rebreaks the given par
382 void redoParagraphInternal(par_type pit);
383 /// used in setlayout
384 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
386 /// Calculate and set the height of the row
387 void setHeightOfRow(par_type, Row & row);
389 // fix the cursor `cur' after a characters has been deleted at `where'
390 // position. Called by deleteEmptyParagraphMechanism
391 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
393 /// delete double space or empty paragraphs around old cursor
394 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
397 void setCounter(Buffer const &, par_type pit);
399 void deleteWordForward(LCursor & cur);
401 void deleteWordBackward(LCursor & cur);
403 void deleteLineForward(LCursor & cur);
405 /// sets row.end to the pos value *after* which a row should break.
406 /// for example, the pos after which isNewLine(pos) == true
407 void rowBreakPoint(par_type pit, Row & row) const;
408 /// sets row.width to the minimum space a row needs on the screen in pixel
409 void setRowWidth(par_type pit, Row & row) const;
410 /// the minimum space a manual label needs on the screen in pixels
411 int labelFill(par_type pit, Row const & row) const;
413 int labelEnd(par_type pit) const;
417 /// set 'number' font property
418 void number(LCursor & cur);
421 /// return the default height of a row in pixels, considering font zoom
422 int defaultRowHeight();
425 std::string expandLabel(LyXTextClass const & textclass,
426 LyXLayout_ptr const & layout, bool appendix);