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