]> git.lyx.org Git - lyx.git/blob - src/Text.h
I'll find a solution for the 'dirList problem', Abdel.
[lyx.git] / src / Text.h
1 // -*- C++ -*-
2 /**
3  * \file Text.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 TEXT_H
15 #define TEXT_H
16
17 #include "ParagraphList.h"
18
19 namespace lyx {
20
21 class Buffer;
22 class BufferParams;
23 class BufferView;
24 class CursorSlice;
25 class DocIterator;
26 class ErrorList;
27 class Font;
28 class FontInfo;
29 class FuncRequest;
30 class FuncStatus;
31 class Inset;
32 class Cursor;
33 class Lexer;
34 class PainterInfo;
35 class Spacing;
36
37
38 /// This class encapsulates the main text data and operations in LyX
39 class Text {
40 public:
41         /// constructor
42         explicit Text();
43
44         /// \return true if there's no content at all.
45         /// \warning a non standard layout on an empty paragraph doesn't
46         // count as empty.
47         bool empty() const;
48
49         ///
50         FontInfo getLayoutFont(Buffer const & buffer, pit_type pit) const;
51         ///
52         FontInfo getLabelFont(Buffer const & buffer,
53                 Paragraph const & par) const;
54         /** Set font of character at position \p pos in paragraph \p pit.
55          *  Must not be called if \p pos denotes an inset with text contents,
56          *  and the inset is not allowed inside a font change (see below).
57          */
58         void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
59                 Font const & font, Font const & display_font);
60
61         /** Needed to propagate font changes to all text cells of insets
62          *  that are not allowed inside a font change (bug 1973).
63          *  Must not be called if \p pos denotes an ordinary character or an
64          *  inset that is alowed inside a font change.
65          *  FIXME: This should be removed, see documentation of noFontChange
66          *  in insetbase.h
67          */
68         void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
69                 Font const & font, bool toggleall = false);
70
71         /// what you expect when pressing \<enter\> at cursor position
72         void breakParagraph(Cursor & cur, bool inverse_logic = false);
73
74         /// set layout over selection
75         void setLayout(Buffer const & buffer, pit_type start, pit_type end,
76                 docstring const & layout);
77         /// Set given layout to current cursor position.
78         /// FIXME: replace Cursor with DocIterator.
79         void setLayout(Cursor & cur, docstring const & layout);
80
81         /// what type of depth change to make
82         enum DEPTH_CHANGE {
83                 INC_DEPTH,
84                 DEC_DEPTH
85         };
86         /// Increase or decrease the nesting depth of the selected paragraph(s)
87         /// FIXME: replace Cursor with DocIterator.
88         void changeDepth(Cursor & cur, DEPTH_CHANGE type);
89
90         /// Returns whether something would be changed by changeDepth
91         /// FIXME: replace Cursor with DocIterator.
92         bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
93
94         /// Set font over selection paragraphs and rebreak.
95         /// FIXME: replace Cursor with DocIterator.
96         void setFont(Cursor & cur, Font const &, bool toggleall = false);
97         /// Set font from \p begin to \p end and rebreak.
98         void setFont(BufferView const & bv, CursorSlice const & begin,
99                 CursorSlice const & end, Font const &,
100                 bool toggleall = false);
101
102         ///
103         void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
104
105         /// ???
106         /// FIXME: replace Cursor with DocIterator.
107         docstring getStringToIndex(Cursor const & cur);
108
109         /// insert a character at cursor position
110         /// FIXME: replace Cursor with DocIterator.
111         void insertChar(Cursor & cur, char_type c);
112         /// insert an inset at cursor position
113         /// FIXME: replace Cursor with DocIterator.
114         void insertInset(Cursor & cur, Inset * inset);
115
116         /// try to handle that request
117         /// FIXME: replace Cursor with DocIterator.
118         void dispatch(Cursor & cur, FuncRequest & cmd);
119         /// do we want to handle this event?
120         bool getStatus(Cursor & cur, FuncRequest const & cmd,
121                 FuncStatus & status) const;
122
123         /// read-only access to individual paragraph
124         Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
125         /// read-write access to individual paragraph
126         Paragraph & getPar(pit_type pit) { return pars_[pit]; }
127         // Returns the current font and depth as a message.
128         /// FIXME: replace Cursor with DocIterator.
129         docstring currentState(Cursor & cur);
130
131         /** Find the word under \c from in the relative location
132          *  defined by \c word_location.
133          *  @param from return here the start of the word
134          *  @param to return here the end of the word
135          */
136         void getWord(CursorSlice & from, CursorSlice & to, word_location const);
137         /// just selects the word the cursor is in
138         void selectWord(Cursor & cur, word_location loc);
139
140         /// what type of change operation to make
141         enum ChangeOp {
142                 ACCEPT,
143                 REJECT
144         };
145         /// accept or reject the selected change
146         void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
147         /// accept the changes within the complete Text
148         void acceptChanges(BufferParams const & bparams);
149         /// reject the changes within the complete Text
150         void rejectChanges(BufferParams const & bparams);
151
152         /// returns true if par was empty and was removed
153         bool setCursor(Cursor & cur, pit_type par, pos_type pos,
154                        bool setfont = true, bool boundary = false);
155         ///
156         void setCursor(CursorSlice &, pit_type par, pos_type pos);
157         ///
158         void setCursorIntern(Cursor & cur, pit_type par,
159                  pos_type pos, bool setfont = true, bool boundary = false);
160
161         ///
162         void recUndo(Cursor & cur, pit_type first, pit_type last) const;
163         ///
164         void recUndo(Cursor & cur, pit_type first) const;
165
166         /// Move cursor one position backwards
167         /**
168          * Returns true if an update is needed after the move.
169          */
170         bool cursorBackward(Cursor & cur);
171         /// Move cursor one position forward
172         /**
173          * Returns true if an update is needed after the move.
174          */
175         bool cursorForward(Cursor & cur);
176         ///
177         bool cursorBackwardOneWord(Cursor & cur);
178         ///
179         bool cursorForwardOneWord(Cursor & cur);
180         /// Delete from cursor up to the end of the current or next word.
181         void deleteWordForward(Cursor & cur);
182         /// Delete from cursor to start of current or prior word.
183         void deleteWordBackward(Cursor & cur);
184         ///
185         bool cursorUpParagraph(Cursor & cur);
186         ///
187         bool cursorDownParagraph(Cursor & cur);
188         ///
189         bool cursorTop(Cursor & cur);
190         ///
191         bool cursorBottom(Cursor & cur);
192         /// Erase character at cursor. Honour change tracking
193         /// FIXME: replace Cursor with DocIterator.
194         bool erase(Cursor & cur);
195         /// Delete character before cursor. Honour CT
196         /// FIXME: replace Cursor with DocIterator.
197         bool backspace(Cursor & cur);
198         // Dissolve the inset under cursor
199         /// FIXME: replace Cursor with DocIterator.
200         bool dissolveInset(Cursor & cur);
201         ///
202         bool selectWordWhenUnderCursor(Cursor & cur, word_location);
203         /// Change the case of the word at cursor position.
204         void changeCase(Cursor & cur, TextCase action);
205         /// Transposes the character at the cursor with the one before it
206         void charsTranspose(Cursor & cur);
207
208         /** the DTP switches for paragraphs. LyX will store the top settings
209          always in the first physical paragraph, the bottom settings in the
210          last. When a paragraph is broken, the top settings rest, the bottom
211          settings are given to the new one.
212          This function will handle a multi-paragraph selection.
213          */
214         void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
215         /// Sets parameters for current or selected paragraphs
216         void setParagraphs(Cursor & cur, ParagraphParameters const & p);
217
218         /* these things are for search and replace */
219
220         /// needed to insert the selection
221         /// FIXME: replace Cursor with DocIterator.
222         void insertStringAsLines(Cursor & cur, docstring const & str);
223         /// needed to insert the selection
224         /// FIXME: replace Cursor with DocIterator.
225         void insertStringAsParagraphs(Cursor & cur, docstring const & str);
226
227         /// access to our paragraphs
228         ParagraphList const & paragraphs() const { return pars_; }
229         ParagraphList & paragraphs() { return pars_; }
230         /// return true if this is the main text
231         bool isMainText(Buffer const &) const;
232
233         ///
234         double spacing(Buffer const & buffer, Paragraph const & par) const;
235         /// make a suggestion for a label
236         /// FIXME: replace Cursor with DocIterator.
237         docstring getPossibleLabel(Cursor & cur) const;
238         /// is this paragraph right-to-left?
239         bool isRTL(Buffer const &, Paragraph const & par) const;
240
241         ///
242         bool checkAndActivateInset(Cursor & cur, bool front);
243
244         ///
245         void write(Buffer const & buf, std::ostream & os) const;
246         /// returns whether we've seen our usual 'end' marker
247         bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
248
249         /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
250         /// \retval true if a change has happened and we need a redraw.
251         /// FIXME: replace Cursor with DocIterator. This is not possible right
252         /// now because recordUndo() is called which needs a Cursor.
253         static bool deleteEmptyParagraphMechanism(Cursor & cur,
254                 Cursor & old, bool & need_anchor_change);
255
256         /// delete double spaces, leading spaces, and empty paragraphs
257         /// from \first to \last paragraph
258         void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
259
260 public:
261         ///
262         ParagraphList pars_;
263
264         ///
265         bool autoBreakRows_;
266 private:
267         /// return past-the-last paragraph influenced by a layout
268         /// change on pit
269         pit_type undoSpan(pit_type pit);
270
271         // fix the cursor `cur' after a characters has been deleted at `where'
272         // position. Called by deleteEmptyParagraphMechanism
273         static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
274
275         // At cursor position 0, try to merge the paragraph with the one before it.
276         // Ignore change tracking, i.e., physically remove the end-of-par character
277         bool backspacePos0(Cursor & cur);
278         /// handle the case where bibitems were deleted
279         bool handleBibitems(Cursor & cur);
280         ///
281         void charInserted(Cursor & cur);
282         /// set 'number' font property
283         void number(Cursor & cur);
284
285         /// paste plain text at current cursor.
286         /// \param str string to paste
287         /// \param asParagraphs whether to paste as paragraphs or as lines
288         void pasteString(Cursor & cur, docstring const & str,
289                         bool asParagraphs);
290 };
291
292 } // namespace lyx
293
294 #endif // LYXTEXT_H