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_fwd.h"
47 /// This class encapsulates the main text data and operations in LyX
51 typedef lyx::pos_type pos_type;
53 typedef lyx::pit_type pit_type;
56 explicit LyXText(BufferView *);
58 void init(BufferView *);
61 LyXFont getFont(Paragraph const & par, pos_type pos) const;
63 LyXFont getLayoutFont(pit_type pit) const;
65 LyXFont getLabelFont(Paragraph const & par) const;
67 void setCharFont(pit_type pit, pos_type pos, LyXFont const & font);
69 void setCharFont(pit_type pit, pos_type pos, LyXFont const & font,
72 /// what you expect when pressing <enter> at cursor position
73 void breakParagraph(LCursor & cur, char keep_layout = 0);
75 /// set layout over selection
76 pit_type setLayout(pit_type start, pit_type end,
77 std::string const & layout);
79 void setLayout(LCursor & cur, std::string const & layout);
81 /// what type of depth change to make
86 /// Increase or decrease the nesting depth of the selected paragraph(s)
87 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
89 /// Returns whether something would be changed by changeDepth
90 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
92 /// Set font over selection paragraphs and rebreak.
93 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
95 /// rebreaks the given par
96 void redoParagraph(pit_type pit);
98 /// returns pos in given par at given x coord
99 pos_type x2pos(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 std::string getStringToIndex(LCursor & cur);
108 /// insert a character at cursor position
109 void insertChar(LCursor & cur, char c);
110 /// insert an inset at cursor position
111 void insertInset(LCursor & cur, InsetBase * inset);
113 /// compute text metrics
114 void metrics(MetricsInfo & mi, Dimension & dim);
115 /// draw text (only used for insets)
116 void draw(PainterInfo & pi, int x, int y) const;
117 /// draw textselection
118 void drawSelection(PainterInfo & pi, int x, int y) const;
120 /// try to handle that request
121 void dispatch(LCursor & cur, FuncRequest & cmd);
122 /// do we want to handle this event?
123 bool getStatus(LCursor & cur, FuncRequest const & cmd,
124 FuncStatus & status) const;
126 /// access to out BufferView. This should go...
128 /// access to out BufferView. This should go...
129 BufferView * bv() const;
131 /// access to individual paragraphs
132 Paragraph & getPar(pit_type par) const;
133 // Returns the current font and depth as a message.
134 std::string LyXText::currentState(LCursor & cur);
136 /** returns row near the specified
137 * y-coordinate in given paragraph (relative to the screen).
139 Row const & getRowNearY(int y, pit_type pit) const;
140 pit_type getPitNearY(int y) const;
142 /** returns the column near the specified x-coordinate of the row
143 x is set to the real beginning of this column
145 pos_type getColumnNearX(pit_type pit,
146 Row const & row, int & x, bool & boundary) const;
148 /** Find the word under \c from in the relative location
149 * defined by \c word_location.
150 * @param from return here the start of the word
151 * @param to return here the end of the word
153 void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
154 /// just selects the word the cursor is in
155 void selectWord(LCursor & cur, lyx::word_location loc);
157 /// accept selected change
158 void acceptChange(LCursor & cur);
159 /// reject selected change
160 void rejectChange(LCursor & cur);
162 /// returns true if par was empty and was removed
163 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
164 bool setfont = true, bool boundary = false);
166 void setCursor(CursorSlice &, pit_type par,
167 pos_type pos, bool boundary = false);
169 void setCursorIntern(LCursor & cur, pit_type par,
170 pos_type pos, bool setfont = true, bool boundary = false);
172 void setCurrentFont(LCursor & cur);
175 void recUndo(pit_type first, pit_type last) const;
177 void recUndo(pit_type first) const;
179 void setCursorFromCoordinates(LCursor & cur, int x, int y);
181 InsetBase * editXY(LCursor & cur, int x, int y) const;
183 void cursorUp(LCursor & cur);
185 void cursorDown(LCursor & cur);
187 void cursorLeft(LCursor & cur);
189 void cursorRight(LCursor & cur);
191 void cursorLeftOneWord(LCursor & cur);
193 void cursorRightOneWord(LCursor & cur);
195 void cursorUpParagraph(LCursor & cur);
197 void cursorDownParagraph(LCursor & cur);
199 void cursorHome(LCursor & cur);
201 void cursorEnd(LCursor & cur);
203 void cursorPrevious(LCursor & cur);
205 void cursorNext(LCursor & cur);
207 void cursorTop(LCursor & cur);
209 void cursorBottom(LCursor & cur);
211 void Delete(LCursor & cur);
213 void backspace(LCursor & cur);
215 bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
221 text_capitalization = 1,
225 /// Change the case of the word at cursor position.
226 void changeCase(LCursor & cur, TextCase action);
228 /** the DTP switches for paragraphs. LyX will store the top settings
229 always in the first physical paragraph, the bottom settings in the
230 last. When a paragraph is broken, the top settings rest, the bottom
231 settings are given to the new one.
233 void setParagraph(LCursor & cur,
234 Spacing const & spacing,
236 std::string const & labelwidthstring,
239 /* these things are for search and replace */
241 /// needed to insert the selection
242 void insertStringAsLines(LCursor & cur, std::string const & str);
243 /// needed to insert the selection
244 void insertStringAsParagraphs(LCursor & cur, std::string const & str);
246 /// Find next inset of some specified type.
247 bool gotoNextInset(LCursor & cur,
248 std::vector<InsetBase_code> const & codes,
249 std::string const & contents = std::string());
251 void gotoInset(LCursor & cur,
252 std::vector<InsetBase_code> const & codes, bool same_content);
254 void gotoInset(LCursor & cur, InsetBase_code code, bool same_content);
256 /// current text width
259 /// current text heigth
262 /// updates all counters
263 void updateCounters();
264 /// Returns an inset if inset was hit, or 0 if not.
265 InsetBase * checkInsetHit(int x, int y) const;
268 int singleWidth(Paragraph const & par, pos_type pos) const;
270 int singleWidth(Paragraph const & par,
271 pos_type pos, char c, LyXFont const & Font) const;
273 /// return the color of the canvas
274 LColor_color backgroundColor() const;
277 * Returns the left beginning of the text.
278 * This information cannot be taken from the layout object, because
279 * in LaTeX the beginning of the text fits in some cases
280 * (for example sections) exactly the label-width.
282 int leftMargin(pit_type pit, pos_type pos) const;
283 int leftMargin(pit_type pit) const;
285 int rightMargin(Paragraph const & par) const;
287 /** this calculates the specified parameters. needed when setting
288 * the cursor and when creating a visible row */
289 RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
291 /// access to our paragraphs
292 ParagraphList & paragraphs() const;
293 /// return true if this is the main text
294 bool isMainText() const;
296 /// return first row of text
297 Row const & firstRow() const;
299 /// is this row the last in the text?
300 bool isLastRow(pit_type pit, Row const & row) const;
301 /// is this row the first in the text?
302 bool isFirstRow(pit_type pit, Row const & row) const;
305 double spacing(Paragraph const & par) const;
306 /// make a suggestion for a label
307 std::string getPossibleLabel(LCursor & cur) const;
308 /// is this paragraph right-to-left?
309 bool isRTL(Paragraph const & par) const;
311 bool checkAndActivateInset(LCursor & cur, bool front);
314 void write(Buffer const & buf, std::ostream & os) const;
315 /// returns whether we've seen our usual 'end' marker
316 bool read(Buffer const & buf, LyXLex & lex);
323 int cursorX(CursorSlice const & cursor) const;
325 int cursorY(CursorSlice const & cursor) const;
328 friend class LyXScreen;
335 /// the current font settings
336 LyXFont current_font;
338 LyXFont real_current_font;
339 /// our buffer's default layout font
340 LyXFont defaultfont_;
342 int background_color_;
344 /// only the top-level LyXText has this non-zero
345 BufferView * bv_owner;
352 /// our 'outermost' Font
358 /// return past-the-last paragraph influenced by a layout
360 pit_type undoSpan(pit_type pit);
362 /// used in setlayout
363 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
365 /// Calculate and set the height of the row
366 void setHeightOfRow(pit_type, Row & row);
368 // fix the cursor `cur' after a characters has been deleted at `where'
369 // position. Called by deleteEmptyParagraphMechanism
370 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
372 /// delete double space or empty paragraphs around old cursor
373 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
376 void setCounter(Buffer const &, pit_type pit);
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(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(pit_type pit, Row & row) const;
389 /// the minimum space a manual label needs on the screen in pixels
390 int labelFill(Paragraph const & par, Row const & row) const;
392 int labelEnd(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();
404 std::string expandLabel(LyXTextClass const & textclass,
405 LyXLayout_ptr const & layout, bool appendix);