]> git.lyx.org Git - lyx.git/blob - src/lyxtext.h
small doxygen fix, remove unused declaration
[lyx.git] / src / lyxtext.h
1 // -*- C++ -*-
2 /**
3  * \file lyxtext.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LYXTEXT_H
15 #define LYXTEXT_H
16
17 #include "Bidi.h"
18 #include "dispatchresult.h"
19 #include "lyxfont.h"
20 #include "layout.h"
21 #include "lyxlayout_ptr_fwd.h"
22 #include "ParagraphList.h"
23
24 #include <iosfwd>
25
26
27 namespace lyx {
28
29 class Buffer;
30 class BufferParams;
31 class BufferView;
32 class CursorSlice;
33 class DocIterator;
34 class ErrorList;
35 class FuncRequest;
36 class FuncStatus;
37 class InsetBase;
38 class LColor_color;
39 class LCursor;
40 class PainterInfo;
41 class Row;
42 class RowMetrics;
43 class Spacing;
44
45
46 /// This class encapsulates the main text data and operations in LyX
47 class LyXText {
48 public:
49         /// constructor
50         explicit LyXText();
51
52         ///
53         LyXFont getFont(Buffer const & buffer, Paragraph const & par,
54                 pos_type pos) const;
55         ///
56         void applyOuterFont(Buffer const & buffer, LyXFont &) const;
57         ///
58         LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
59         ///
60         LyXFont getLabelFont(Buffer const & buffer,
61                 Paragraph const & par) const;
62         ///
63         void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
64                 LyXFont const & font);
65         ///
66         void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
67                 LyXFont const & font, bool toggleall);
68
69         /// what you expect when pressing \<enter\> at cursor position
70         void breakParagraph(LCursor & cur, bool keep_layout = false);
71
72         /// set layout over selection
73         void setLayout(Buffer const & buffer, pit_type start, pit_type end,
74                 std::string const & layout);
75         /// Set given layout to current cursor position.
76         /// FIXME: replace LCursor with DocIterator.
77         void setLayout(LCursor & cur, std::string const & layout);
78
79         /// what type of depth change to make
80         enum DEPTH_CHANGE {
81                 INC_DEPTH,
82                 DEC_DEPTH
83         };
84         /// Increase or decrease the nesting depth of the selected paragraph(s)
85         /// FIXME: replace LCursor with DocIterator.
86         void changeDepth(LCursor & cur, DEPTH_CHANGE type);
87
88         /// Returns whether something would be changed by changeDepth
89         /// FIXME: replace LCursor with DocIterator.
90         bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
91
92         /// Set font over selection paragraphs and rebreak.
93         /// FIXME: replace LCursor with DocIterator.
94         void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
95
96         ///
97         void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
98
99         /// ???
100         /// FIXME: replace LCursor with DocIterator.
101         docstring getStringToIndex(LCursor const & cur);
102
103         /// insert a character at cursor position
104         /// FIXME: replace LCursor with DocIterator.
105         void insertChar(LCursor & cur, char_type c);
106         /// insert an inset at cursor position
107         /// FIXME: replace LCursor with DocIterator.
108         void insertInset(LCursor & cur, InsetBase * inset);
109
110         /// draw text (only used for insets)
111         void draw(PainterInfo & pi, int x, int y) const;
112         /// draw textselection
113         void drawSelection(PainterInfo & pi, int x, int y) const;
114
115         /// try to handle that request
116         /// FIXME: replace LCursor with DocIterator.
117         void dispatch(LCursor & cur, FuncRequest & cmd);
118         /// do we want to handle this event?
119         bool getStatus(LCursor & cur, FuncRequest const & cmd,
120                 FuncStatus & status) const;
121
122         /// read-only access to individual paragraph
123         Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
124         /// read-write access to individual paragraph
125         Paragraph & getPar(pit_type pit) { return pars_[pit]; }
126         // Returns the current font and depth as a message.
127         /// FIXME: replace LCursor with DocIterator.
128         docstring currentState(LCursor & cur);
129
130         /** returns row near the specified
131           * y-coordinate in given paragraph (relative to the screen).
132           */
133         /// FIXME: move to TextMetrics.
134         Row const & getRowNearY(BufferView const & bv, int y,
135                 pit_type pit) const;
136
137         /// returns the paragraph number closest to screen y-coordinate.
138         /// This method uses the BufferView CoordCache to locate the
139         /// paragraph. The y-coodinate is allowed to be off-screen and
140         /// the CoordCache will be automatically updated if needed. This is
141         /// the reason why we need a non const BufferView.
142         /// FIXME: move to TextMetrics.
143         pit_type getPitNearY(BufferView & bv, int y) const;
144
145         /** Find the word under \c from in the relative location
146          *  defined by \c word_location.
147          *  @param from return here the start of the word
148          *  @param to return here the end of the word
149          */
150         void getWord(CursorSlice & from, CursorSlice & to, word_location const);
151         /// just selects the word the cursor is in
152         void selectWord(LCursor & cur, word_location loc);
153
154         /// what type of change operation to make 
155         enum ChangeOp {
156                 ACCEPT,
157                 REJECT
158         };
159         /// accept or reject the selected change
160         void acceptOrRejectChanges(LCursor & cur, ChangeOp op);
161         /// accept the changes within the complete LyXText
162         void acceptChanges(BufferParams const & bparams);
163         /// reject the changes within the complete LyXText
164         void rejectChanges(BufferParams const & bparams);
165
166         /// returns true if par was empty and was removed
167         bool setCursor(LCursor & cur, pit_type par, pos_type pos,
168                        bool setfont = true, bool boundary = false);
169         ///
170         void setCursor(CursorSlice &, pit_type par, pos_type pos);
171         ///
172         void setCursorIntern(LCursor & cur, pit_type par,
173                  pos_type pos, bool setfont = true, bool boundary = false);
174         ///
175         void setCurrentFont(LCursor & cur);
176
177         ///
178         void recUndo(LCursor & cur, pit_type first, pit_type last) const;
179         ///
180         void recUndo(LCursor & cur, pit_type first) const;
181
182         /// sets cursor only within this LyXText.
183         /// x,y are screen coordinates
184         void setCursorFromCoordinates(LCursor & cur, int x, int y);
185
186         /// sets cursor recursively descending into nested editable insets
187         /**
188         \return the inset pointer if x,y is covering that inset
189         \param x,y are absolute screen coordinates.
190         \retval inset is non-null if the cursor is positionned inside
191         */
192         /// FIXME: move to TextMetrics.
193         /// FIXME: cleanup to use BufferView::getCoveringInset() and
194         /// setCursorFromCoordinates() instead of checkInsetHit().
195         InsetBase * editXY(LCursor & cur, int x, int y);
196         
197         /// Move cursor one line up.
198         /**
199          * Returns true if an update is needed after the move.
200          */
201         /// FIXME: move to TextMetrics.
202         bool cursorUp(LCursor & cur);
203         /// Move cursor one line down.
204         /**
205          * Returns true if an update is needed after the move.
206          */
207         /// FIXME: move to TextMetrics.
208         bool cursorDown(LCursor & cur);
209         /// Move cursor one position left
210         /**
211          * Returns true if an update is needed after the move.
212          */
213         bool cursorLeft(LCursor & cur);
214         /// Move cursor one position right
215         /**
216          * Returns true if an update is needed after the move.
217          */
218         bool cursorRight(LCursor & cur);
219         ///
220         bool cursorLeftOneWord(LCursor & cur);
221         ///
222         bool cursorRightOneWord(LCursor & cur);
223         ///
224         bool cursorUpParagraph(LCursor & cur);
225         ///
226         bool cursorDownParagraph(LCursor & cur);
227         ///
228         /// FIXME: move to TextMetrics.
229         bool cursorHome(LCursor & cur);
230         ///
231         /// FIXME: move to TextMetrics.
232         bool cursorEnd(LCursor & cur);
233         ///
234         void cursorPrevious(LCursor & cur);
235         ///
236         void cursorNext(LCursor & cur);
237         ///
238         bool cursorTop(LCursor & cur);
239         ///
240         bool cursorBottom(LCursor & cur);
241         /// Erase character at cursor. Honour change tracking
242         /// FIXME: replace LCursor with DocIterator.
243         bool erase(LCursor & cur);
244         /// Delete character before cursor. Honour CT
245         /// FIXME: replace LCursor with DocIterator.
246         bool backspace(LCursor & cur);
247         // Dissolve the inset under cursor
248         /// FIXME: replace LCursor with DocIterator.
249         bool dissolveInset(LCursor & cur);
250         ///
251         bool selectWordWhenUnderCursor(LCursor & cur, word_location);
252         ///
253         enum TextCase {
254                 ///
255                 text_lowercase = 0,
256                 ///
257                 text_capitalization = 1,
258                 ///
259                 text_uppercase = 2
260         };
261         /// Change the case of the word at cursor position.
262         void changeCase(LCursor & cur, TextCase action);
263         /// Transposes the character at the cursor with the one before it
264         void charsTranspose(LCursor & cur);
265
266         /** the DTP switches for paragraphs. LyX will store the top settings
267          always in the first physical paragraph, the bottom settings in the
268          last. When a paragraph is broken, the top settings rest, the bottom
269          settings are given to the new one.
270          */
271         void setParagraph(LCursor & cur,
272                           Spacing const & spacing,
273                           LyXAlignment align,
274                           docstring const & labelwidthstring,
275                           bool noindent);
276
277         /* these things are for search and replace */
278
279         /// needed to insert the selection
280         /// FIXME: replace LCursor with DocIterator.
281         void insertStringAsLines(LCursor & cur, docstring const & str);
282         /// needed to insert the selection
283         /// FIXME: replace LCursor with DocIterator.
284         void insertStringAsParagraphs(LCursor & cur, docstring const & str);
285
286         /// Returns an inset if inset was hit, or 0 if not.
287         /// \warning This method is not recursive! It will return the
288         /// outermost inset within this LyXText.
289         /// \sa BufferView::getCoveringInset() to get the innermost inset.
290         InsetBase * checkInsetHit(BufferView &, int x, int y);
291
292         ///
293         /// FIXME: move to TextMetrics.
294         int singleWidth(Buffer const &, Paragraph const & par,
295                 pos_type pos) const;
296         ///
297         /// FIXME: move to TextMetrics.
298         int singleWidth(Paragraph const & par, pos_type pos, char_type c,
299                 LyXFont const & Font) const;
300
301         /// return the color of the canvas
302         LColor_color backgroundColor() const;
303
304         /**
305          * Returns the left beginning of the text.
306          * This information cannot be taken from the layout object, because
307          * in LaTeX the beginning of the text fits in some cases
308          * (for example sections) exactly the label-width.
309          */
310         /// FIXME: move to TextMetrics.
311         int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
312         int leftMargin(Buffer const &, int max_width, pit_type pit) const;
313
314         /// access to our paragraphs
315         ParagraphList const & paragraphs() const { return pars_; }
316         ParagraphList & paragraphs() { return pars_; }
317         /// return true if this is the main text
318         bool isMainText(Buffer const &) const;
319
320         /// is this row the last in the text?
321         /// FIXME: move to TextMetrics.
322         bool isLastRow(pit_type pit, Row const & row) const;
323         /// is this row the first in the text?
324         /// FIXME: move to TextMetrics.
325         bool isFirstRow(pit_type pit, Row const & row) const;
326
327         ///
328         double spacing(Buffer const & buffer, Paragraph const & par) const;
329         /// make a suggestion for a label
330         /// FIXME: replace LCursor with DocIterator.
331         docstring getPossibleLabel(LCursor & cur) const;
332         /// is this paragraph right-to-left?
333         bool isRTL(Buffer const &, Paragraph const & par) const;
334         ///
335         bool checkAndActivateInset(LCursor & cur, bool front);
336
337         ///
338         void write(Buffer const & buf, std::ostream & os) const;
339         /// returns whether we've seen our usual 'end' marker
340         bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
341
342         ///
343         /// FIXME: move to TextMetrics.
344         int cursorX(BufferView const &, CursorSlice const & cursor,
345                 bool boundary) const;
346         ///
347         /// FIXME: move to TextMetrics.
348         int cursorY(BufferView const & bv, CursorSlice const & cursor,
349                 bool boundary) const;
350
351         /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
352         /// \retval true if a change has happened and we need a redraw.
353         /// FIXME: replace LCursor with DocIterator. This is not possible right
354         /// now because recordUndo() is called which needs a LCursor.
355         static bool deleteEmptyParagraphMechanism(LCursor & cur,
356                 LCursor & old, bool & need_anchor_change);
357
358         /// delete double spaces, leading spaces, and empty paragraphs
359         /// from \first to \last paragraph
360         void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
361
362 public:
363         /// the current font settings
364         LyXFont current_font;
365         /// the current font
366         LyXFont real_current_font;
367         ///
368         int background_color_;
369
370         ///
371         mutable Bidi bidi;
372         ///
373         ParagraphList pars_;
374
375         /// our 'outermost' font. This is handed down from the surrounding
376         // inset through the pi/mi parameter (pi.base.font)
377         LyXFont font_;
378
379         ///
380         bool autoBreakRows_;
381 private:
382         /// return past-the-last paragraph influenced by a layout
383         /// change on pit
384         pit_type undoSpan(pit_type pit);
385
386         // fix the cursor `cur' after a characters has been deleted at `where'
387         // position. Called by deleteEmptyParagraphMechanism
388         static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
389
390         // At cursor position 0, try to merge the paragraph with the one before it.
391         // Ignore change tracking, i.e., physically remove the end-of-par character
392         bool backspacePos0(LCursor & cur);
393
394         ///
395         void deleteWordForward(LCursor & cur);
396         ///
397         void deleteWordBackward(LCursor & cur);
398         ///
399         void deleteLineForward(LCursor & cur);
400         ///
401         void charInserted();
402         /// set 'number' font property
403         void number(LCursor & cur);
404
405         /// paste plain text at current cursor.
406         /// \param str string to paste
407         /// \param asParagraphs whether to paste as paragraphs or as lines
408         void pasteString(LCursor & cur, docstring const & str,
409                         bool asParagraphs);
410 };
411
412 } // namespace lyx
413
414 #endif // LYXTEXT_H