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 "ParagraphList_fwd.h"
46 /// This class encapsulates the main text data and operations in LyX
50 typedef lyx::pos_type pos_type;
52 typedef lyx::par_type par_type;
55 explicit LyXText(BufferView *);
57 void init(BufferView *);
59 /// update y coordinate cache of all paragraphs
60 void updateParPositions();
62 LyXFont getFont(Paragraph const & par, pos_type pos) const;
64 LyXFont getLayoutFont(par_type pit) const;
66 LyXFont getLabelFont(Paragraph const & par) const;
68 void setCharFont(par_type pit, pos_type pos, LyXFont const & font);
70 void setCharFont(par_type pit, pos_type pos, LyXFont const & font,
73 /// what you expect when pressing <enter> at cursor position
74 void breakParagraph(LCursor & cur, char keep_layout = 0);
76 /// set layout over selection
77 par_type setLayout(par_type start, par_type end,
78 std::string const & layout);
80 void setLayout(LCursor & cur, std::string const & layout);
82 /// what type of depth change to make
87 /// Increase or decrease the nesting depth of the selected paragraph(s)
88 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
90 /// Returns whether something would be changed by changeDepth
91 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
93 /// Set font over selection paragraphs and rebreak.
94 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
96 /// rebreaks all paragaphs between the given pars.
97 void redoParagraphs(par_type begin, par_type end);
98 /// rebreaks the given par
99 void redoParagraph(par_type pit);
100 /// rebreaks the cursor par
101 void redoParagraph(LCursor & cur);
104 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
107 std::string getStringToIndex(LCursor & cur);
109 /// insert a character at cursor position
110 void insertChar(LCursor & cur, char c);
111 /// insert an inset at cursor position
112 void insertInset(LCursor & cur, InsetBase * inset);
114 /// a full rebreak of the whole text
116 /// compute text metrics
117 void metrics(MetricsInfo & mi, Dimension & dim);
118 /// draw text (only used for insets)
119 void draw(PainterInfo & pi, int x, int y) const;
120 /// draw textselection
121 void drawSelection(PainterInfo & pi, int x, int y) const;
122 /// returns distance of this cell to the point given by x and y
123 // assumes valid position and size cache
124 int dist(int x, int y) const;
126 /// try to handle that request
127 void dispatch(LCursor & cur, FuncRequest & cmd);
128 /// do we want to handle this event?
129 bool getStatus(LCursor & cur, FuncRequest const & cmd,
130 FuncStatus & status) const;
132 /// access to out BufferView. This should go...
134 /// access to out BufferView. This should go...
135 BufferView * bv() const;
137 /// access to individual paragraphs
138 Paragraph & getPar(par_type par) const;
139 // Returns the current font and depth as a message.
140 std::string LyXText::currentState(LCursor & cur);
142 /** returns an iterator pointing to the row near the specified
143 * y-coordinate (relative to the whole text). y is set to the
144 * real beginning of this row
146 Row const & getRowNearY(int y, par_type & pit) const;
148 /** returns the column near the specified x-coordinate of the row
149 x is set to the real beginning of this column
151 pos_type getColumnNearX(par_type pit,
152 Row const & row, int & x, bool & boundary) const;
154 /** Find the word under \c from in the relative location
155 * defined by \c word_location.
156 * @param from return here the start of the word
157 * @param to return here the end of the word
159 void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
160 /// just selects the word the cursor is in
161 void selectWord(LCursor & cur, lyx::word_location loc);
163 /// accept selected change
164 void acceptChange(LCursor & cur);
165 /// reject selected change
166 void rejectChange(LCursor & cur);
168 /// returns true if par was empty and was removed
169 bool setCursor(LCursor & cur, par_type par, pos_type pos,
170 bool setfont = true, bool boundary = false);
172 void setCursor(CursorSlice &, par_type par,
173 pos_type pos, bool boundary = false);
175 void setCursorIntern(LCursor & cur, par_type par,
176 pos_type pos, bool setfont = true, bool boundary = false);
178 void setCurrentFont(LCursor & cur);
181 void recUndo(par_type first, par_type last) const;
183 void recUndo(par_type first) const;
185 void setCursorFromCoordinates(LCursor & cur, int x, int y);
187 InsetBase * editXY(LCursor & cur, int x, int y) const;
189 void cursorUp(LCursor & cur);
191 void cursorDown(LCursor & cur);
193 void cursorLeft(LCursor & cur);
195 void cursorRight(LCursor & cur);
197 void cursorLeftOneWord(LCursor & cur);
199 void cursorRightOneWord(LCursor & cur);
201 void cursorUpParagraph(LCursor & cur);
203 void cursorDownParagraph(LCursor & cur);
205 void cursorHome(LCursor & cur);
207 void cursorEnd(LCursor & cur);
209 void cursorPrevious(LCursor & cur);
211 void cursorNext(LCursor & cur);
213 void cursorTop(LCursor & cur);
215 void cursorBottom(LCursor & cur);
217 void Delete(LCursor & cur);
219 void backspace(LCursor & cur);
221 bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
227 text_capitalization = 1,
231 /// Change the case of the word at cursor position.
232 void changeCase(LCursor & cur, TextCase action);
234 /** the DTP switches for paragraphs. LyX will store the top settings
235 always in the first physical paragraph, the bottom settings in the
236 last. When a paragraph is broken, the top settings rest, the bottom
237 settings are given to the new one.
239 void setParagraph(LCursor & cur,
240 Spacing const & spacing,
242 std::string const & labelwidthstring,
245 /* these things are for search and replace */
247 /// needed to insert the selection
248 void insertStringAsLines(LCursor & cur, std::string const & str);
249 /// needed to insert the selection
250 void insertStringAsParagraphs(LCursor & cur, std::string const & str);
252 /// Find next inset of some specified type.
253 bool gotoNextInset(LCursor & cur,
254 std::vector<InsetOld_code> const & codes,
255 std::string const & contents = std::string());
257 void gotoInset(LCursor & cur,
258 std::vector<InsetOld_code> const & codes, bool same_content);
260 void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
262 /// current text width
265 /// current text heigth
268 /// updates all counters
269 void updateCounters();
270 /// Returns an inset if inset was hit, or 0 if not.
271 InsetBase * checkInsetHit(int x, int y) const;
274 int singleWidth(Paragraph const & par, pos_type pos) const;
276 int singleWidth(Paragraph const & par,
277 pos_type pos, char c, LyXFont const & Font) const;
279 /// return the color of the canvas
280 LColor_color backgroundColor() const;
283 * Returns the left beginning of the text.
284 * This information cannot be taken from the layout object, because
285 * in LaTeX the beginning of the text fits in some cases
286 * (for example sections) exactly the label-width.
288 int leftMargin(par_type pit, pos_type pos) const;
289 int leftMargin(par_type pit) const;
291 int rightMargin(Paragraph const & par) const;
293 /** this calculates the specified parameters. needed when setting
294 * the cursor and when creating a visible row */
295 RowMetrics computeRowMetrics(par_type pit, Row const & row) const;
297 /// access to our paragraphs
298 ParagraphList & paragraphs() const;
299 /// return true if this is the main text
300 bool isMainText() const;
302 /// return first row of text
303 Row const & firstRow() const;
305 /// is this row the last in the text?
306 bool isLastRow(par_type pit, Row const & row) const;
307 /// is this row the first in the text?
308 bool isFirstRow(par_type pit, Row const & row) const;
311 double spacing(Paragraph const & par) const;
312 /// make a suggestion for a label
313 std::string getPossibleLabel(LCursor & cur) const;
314 /// is this paragraph right-to-left?
315 bool isRTL(Paragraph const & par) const;
317 bool checkAndActivateInset(LCursor & cur, bool front);
320 void write(Buffer const & buf, std::ostream & os) const;
321 /// returns whether we've seen our usual 'end' marker
322 bool read(Buffer const & buf, LyXLex & lex);
329 int cursorX(CursorSlice const & cursor) const;
331 int cursorY(CursorSlice const & cursor) const;
334 friend class LyXScreen;
343 /// the current font settings
344 LyXFont current_font;
346 LyXFont real_current_font;
347 /// our buffer's default layout font
348 LyXFont defaultfont_;
350 int background_color_;
352 /// only the top-level LyXText has this non-zero
353 BufferView * bv_owner;
360 /// absolute document pixel coordinates of this LyXText
364 /// our 'outermost' Font
368 /// return past-the-last paragraph influenced by a layout
370 par_type undoSpan(par_type pit);
372 /// rebreaks the given par
373 void redoParagraphInternal(par_type pit);
374 /// used in setlayout
375 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
377 /// Calculate and set the height of the row
378 void setHeightOfRow(par_type, Row & row);
380 // fix the cursor `cur' after a characters has been deleted at `where'
381 // position. Called by deleteEmptyParagraphMechanism
382 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
384 /// delete double space or empty paragraphs around old cursor
385 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
388 void setCounter(Buffer const &, par_type pit);
390 void deleteWordForward(LCursor & cur);
392 void deleteWordBackward(LCursor & cur);
394 void deleteLineForward(LCursor & cur);
396 /// sets row.end to the pos value *after* which a row should break.
397 /// for example, the pos after which isNewLine(pos) == true
398 void rowBreakPoint(par_type pit, Row & row) const;
399 /// sets row.width to the minimum space a row needs on the screen in pixel
400 void setRowWidth(par_type pit, Row & row) const;
401 /// the minimum space a manual label needs on the screen in pixels
402 int labelFill(Paragraph const & par, Row const & row) const;
404 int labelEnd(par_type pit) const;
408 /// set 'number' font property
409 void number(LCursor & cur);
412 /// return the default height of a row in pixels, considering font zoom
413 int defaultRowHeight();
416 std::string expandLabel(LyXTextClass const & textclass,
417 LyXLayout_ptr const & layout, bool appendix);