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"
24 #include "RowList_fwd.h"
48 /// This class encapsulates the main text data and operations in LyX
52 LyXText(BufferView *, bool ininset);
54 void init(BufferView *);
57 /// update y coordinate cache of all paragraphs
58 void updateParPositions();
60 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
62 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
64 LyXFont getLabelFont(ParagraphList::iterator pit) const;
66 void setCharFont(ParagraphList::iterator pit,
67 lyx::pos_type pos, LyXFont const & font);
68 void setCharFont(ParagraphList::iterator pit,
70 LyXFont const & font, bool toggleall);
72 /// what you expect when pressing <enter> at cursor position
73 void breakParagraph(ParagraphList & paragraphs, char keep_layout = 0);
75 /** set layout over selection and make a total rebreak of
78 ParagraphList::iterator
79 setLayout(ParagraphList::iterator start,
80 ParagraphList::iterator end,
81 std::string const & layout);
83 void setLayout(std::string const & layout);
85 /// Increase or decrease the nesting depth of the selected paragraph(s)
86 void changeDepth(bv_funcs::DEPTH_CHANGE type);
88 /// Returns whether something would be changed by changeDepth
89 bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type);
91 /// get the depth at current cursor position
94 /** set font over selection and make a total rebreak of those
96 toggleall defaults to false.
98 void setFont(LyXFont const &, bool toggleall = false);
100 /// rebreaks all paragaphs between the given pars.
101 void redoParagraphs(ParagraphList::iterator begin,
102 ParagraphList::iterator end);
103 /// rebreaks the given par
104 void redoParagraph(ParagraphList::iterator pit);
106 /// rebreaks the cursor par
107 void redoParagraph();
110 void toggleFree(LyXFont const &, bool toggleall = false);
113 std::string getStringToIndex();
115 /** insert a character, moves all the following breaks in the
116 same Paragraph one to the right and make a little rebreak
118 void insertChar(char c);
120 void insertInset(InsetBase * inset);
122 /// a full rebreak of the whole text
124 /// compute text metrics
125 void metrics(MetricsInfo & mi, Dimension & dim);
126 /// draw text (only used for insets)
127 void draw(PainterInfo & pi, int x, int y) const;
129 /// try to handle that request
130 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
134 BufferView * bv() const;
136 friend class LyXScreen;
138 /// returns an iterator pointing to a cursor paragraph
139 ParagraphList::iterator getPar(CursorSlice const & cursor) const;
141 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
143 int parOffset(ParagraphList::iterator pit) const;
145 ParagraphList::iterator cursorPar() const;
147 RowList::iterator cursorRow() const;
149 /** returns an iterator pointing to the row near the specified
150 * y-coordinate (relative to the whole text). y is set to the
151 * real beginning of this row
153 RowList::iterator getRowNearY(int y,
154 ParagraphList::iterator & pit) const;
156 /** returns the column near the specified x-coordinate of the row
157 x is set to the real beginning of this column
159 lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
160 Row const & row, int & x, bool & boundary) const;
162 /** Find the word under \c from in the relative location
163 * defined by \c word_location.
164 * @param from return here the start of the word
165 * @param to return here the end of the word
167 void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
168 /// just selects the word the cursor is in
169 void selectWord(lyx::word_location loc);
170 /// returns the inset at cursor (if it exists), 0 otherwise
171 InsetBase * getInset() const;
173 /// accept selected change
176 /// reject selected change
180 void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
181 /// returns true if par was empty and was removed
182 bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
183 bool setfont = true, bool boundary = false);
185 void setCursor(CursorSlice &, lyx::paroffset_type par,
186 lyx::pos_type pos, bool boundary = false);
188 void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
189 bool setfont = true, bool boundary = false);
191 void setCurrentFont();
194 void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
196 void recUndo(lyx::paroffset_type first) const;
198 void setCursorFromCoordinates(int x, int y);
200 void setCursorFromCoordinates(CursorSlice &, int x, int y);
202 void cursorUp(bool selecting = false);
204 void cursorDown(bool selecting = false);
206 bool cursorLeft(bool internal = true);
208 bool cursorRight(bool internal = true);
210 void cursorLeftOneWord();
212 void cursorRightOneWord();
214 void cursorUpParagraph();
216 void cursorDownParagraph();
222 void cursorPrevious();
234 bool selectWordWhenUnderCursor(lyx::word_location);
240 text_capitalization = 1,
244 /// Change the case of the word at cursor position.
245 void changeCase(TextCase action);
250 void cutSelection(bool doclear = true, bool realcut = true);
252 void copySelection();
254 void pasteSelection(size_t sel_index = 0);
256 /** the DTP switches for paragraphs. LyX will store the top settings
257 always in the first physical paragraph, the bottom settings in the
258 last. When a paragraph is broken, the top settings rest, the bottom
259 settings are given to the new one.
262 Spacing const & spacing,
264 std::string const & labelwidthstring,
267 /* these things are for search and replace */
270 * Sets the selection from the current cursor position to length
271 * characters to the right. No safety checks.
273 void setSelectionRange(lyx::pos_type length);
275 /** simple replacing. The font of the first selected character
278 void replaceSelectionWithString(std::string const & str);
280 /// needed to insert the selection
281 void insertStringAsLines(std::string const & str);
282 /// needed to insert the selection
283 void insertStringAsParagraphs(std::string const & str);
285 /// Find next inset of some specified type.
286 bool gotoNextInset(std::vector<InsetOld_code> const & codes,
287 std::string const & contents = std::string());
289 void gotoInset(std::vector<InsetOld_code> const & codes,
292 void gotoInset(InsetOld_code code, bool same_content);
294 /// current max text width
295 int textWidth() const;
297 /// updates all counters
298 void updateCounters();
299 /// Returns an inset if inset was hit, or 0 if not.
300 InsetBase * checkInsetHit(int x, int y);
303 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
305 int singleWidth(ParagraphList::iterator pit,
306 lyx::pos_type pos, char c, LyXFont const & Font) const;
308 /// return the color of the canvas
309 LColor_color backgroundColor() const;
312 * Returns the left beginning of the text.
313 * This information cannot be taken from the layout object, because
314 * in LaTeX the beginning of the text fits in some cases
315 * (for example sections) exactly the label-width.
317 int leftMargin(ParagraphList::iterator pit, lyx::pos_type pos) const;
318 int leftMargin(ParagraphList::iterator pit) const;
320 int rightMargin(Paragraph const & par) const;
322 /** this calculates the specified parameters. needed when setting
323 * the cursor and when creating a visible row */
324 void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
327 // special owner functions
329 ParagraphList & paragraphs() const;
331 /// return true if this is owned by an inset.
332 bool isInInset() const;
335 ParagraphList::iterator firstPar() const;
337 ParagraphList::iterator lastPar() const;
339 ParagraphList::iterator endPar() const;
341 /// return first row of text
342 RowList::iterator firstRow() const;
343 /// return last row of text
344 RowList::iterator lastRow() const;
345 /// return row "behind" last row of text
346 RowList::iterator endRow() const;
347 /// return next row crossing paragraph boundaries
348 void nextRow(ParagraphList::iterator & pit,
349 RowList::iterator & rit) const;
350 /// return previous row crossing paragraph boundaries
351 void previousRow(ParagraphList::iterator & pit,
352 RowList::iterator & rit) const;
354 /// is this row the last in the text?
355 bool isLastRow(ParagraphList::iterator pit, Row const & row) const;
356 /// is this row the first in the text?
357 bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
360 std::string selectionAsString(Buffer const & buffer, bool label) const;
362 double spacing(Paragraph const &) const;
364 void cursorLeftOneWord(CursorSlice &);
366 void cursorRightOneWord(CursorSlice &);
369 DispatchResult moveRight();
371 DispatchResult moveLeft();
373 DispatchResult moveRightIntern(bool front,
374 bool activate_inset, bool selecting);
376 DispatchResult moveLeftIntern(bool front,
377 bool activate_inset, bool selecting);
379 DispatchResult moveUp();
381 DispatchResult moveDown();
383 bool checkAndActivateInset(bool front);
386 void write(Buffer const & buf, std::ostream & os) const;
387 /// returns whether we've seen our usual 'end' marker
388 bool read(Buffer const & buf, LyXLex & lex);
399 int cursorX(CursorSlice const & cursor) const;
401 int cursorY(CursorSlice const & cursor) const;
403 /// the topmost cursor slice
404 CursorSlice & cursor();
405 /// the topmost cursor slice
406 CursorSlice const & cursor() const;
407 /// access to the selection anchor
408 CursorSlice & anchor();
409 /// access to the selection anchor
410 CursorSlice const & anchor() const;
419 /// the current font settings
420 LyXFont current_font;
422 LyXFont real_current_font;
423 /// our buffer's default layout font
424 LyXFont defaultfont_;
426 int background_color_;
428 /// only the top-level LyXText has this non-zero
429 BufferView * bv_owner;
436 ParagraphList paragraphs_;
438 /// absolute document pixel coordinates of this LyXText
442 /// our 'outermost' Font
447 /// return past-the-last paragraph influenced by a layout
449 ParagraphList::iterator undoSpan(ParagraphList::iterator pit);
451 /// rebreaks the given par
452 void redoParagraphInternal(ParagraphList::iterator pit);
453 /// used in setlayout
454 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
456 /// Calculate and set the height of the row
457 void setHeightOfRow(ParagraphList::iterator, Row & row);
459 // fix the cursor `cur' after a characters has been deleted at `where'
460 // position. Called by deleteEmptyParagraphMechanism
461 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
463 /// delete double space (false) or empty paragraphs (true) around old_cursor
464 bool deleteEmptyParagraphMechanism(CursorSlice const & old_cursor);
467 void setCounter(Buffer const &, ParagraphList::iterator pit);
469 void deleteWordForward();
471 void deleteWordBackward();
473 void deleteLineForward();
475 /// sets row.end to the pos value *after* which a row should break.
476 /// for example, the pos after which isNewLine(pos) == true
477 void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
479 /// sets row.witdh to the minimum space a row needs on the screen in pixel
480 void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
483 * returns the minimum space a manual label needs on the
486 int labelFill(ParagraphList::iterator pit, Row const & row) const;
489 int labelEnd(ParagraphList::iterator pit) const;
493 /// set 'number' font property
495 /// is the cursor paragraph right-to-left?
499 /// return the default height of a row in pixels, considering font zoom
500 extern int defaultRowHeight();
503 std::string expandLabel(LyXTextClass const & textclass,
504 LyXLayout_ptr const & layout, bool appendix);