]> git.lyx.org Git - lyx.git/blob - src/lyxtext.h
fix reading the author field.
[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 "bufferview_funcs.h"
18 #include "Bidi.h"
19 #include "dispatchresult.h"
20 #include "lyxfont.h"
21 #include "layout.h"
22 #include "lyxlayout_ptr_fwd.h"
23 #include "ParagraphList_fwd.h"
24
25 #include <iosfwd>
26
27 class Buffer;
28 class BufferParams;
29 class BufferView;
30 class CursorSlice;
31 class Dimension;
32 class InsetBase;
33 class InsetOld_code;
34 class FuncRequest;
35 class FuncStatus;
36 class LColor_color;
37 class LCursor;
38 class LyXTextClass;
39 class MetricsInfo;
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         ///
50         typedef lyx::pos_type pos_type;
51         ///
52         typedef lyx::par_type par_type;
53
54         /// constructor
55         explicit LyXText(BufferView *);
56         ///
57         void init(BufferView *);
58
59         /// update y coordinate cache of all paragraphs
60         void updateParPositions();
61         ///
62         LyXFont getFont(Paragraph const & par, pos_type pos) const;
63         ///
64         LyXFont getLayoutFont(par_type pit) const;
65         ///
66         LyXFont getLabelFont(Paragraph const & par) const;
67         ///
68         void setCharFont(par_type pit, pos_type pos, LyXFont const & font);
69         ///
70         void setCharFont(par_type pit, pos_type pos, LyXFont const & font,
71                 bool toggleall);
72
73         /// what you expect when pressing <enter> at cursor position
74         void breakParagraph(LCursor & cur, char keep_layout = 0);
75
76         /// set layout over selection
77         par_type setLayout(par_type start, par_type end,
78                 std::string const & layout);
79         ///
80         void setLayout(LCursor & cur, std::string const & layout);
81
82         /// what type of depth change to make
83         enum DEPTH_CHANGE {
84                 INC_DEPTH,
85                 DEC_DEPTH
86         };
87         /// Increase or decrease the nesting depth of the selected paragraph(s)
88         void changeDepth(LCursor & cur, DEPTH_CHANGE type);
89
90         /// Returns whether something would be changed by changeDepth
91         bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
92
93         /// Set font over selection paragraphs and rebreak.
94         void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
95
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);
102
103         /// returns pos in given par at given x coord
104         pos_type x2pos(par_type pit, int row, int x) const;
105         int pos2x(par_type pit, pos_type pos) const;
106
107         ///
108         void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
109
110         ///
111         std::string getStringToIndex(LCursor & cur);
112
113         /// insert a character at cursor position
114         void insertChar(LCursor & cur, char c);
115         /// insert an inset at cursor position
116         void insertInset(LCursor & cur, InsetBase * inset);
117
118         /// a full rebreak of the whole text
119         void fullRebreak();
120         /// compute text metrics
121         void metrics(MetricsInfo & mi, Dimension & dim);
122         /// draw text (only used for insets)
123         void draw(PainterInfo & pi, int x, int y) const;
124         /// draw textselection
125         void drawSelection(PainterInfo & pi, int x, int y) const;
126         /// returns distance of this cell to the point given by x and y
127         // assumes valid position and size cache
128         int dist(int x, int y) const;
129
130         /// try to handle that request
131         void dispatch(LCursor & cur, FuncRequest & cmd);
132         /// do we want to handle this event?
133         bool getStatus(LCursor & cur, FuncRequest const & cmd,
134                 FuncStatus & status) const;
135
136         /// access to out BufferView. This should go...
137         BufferView * bv();
138         /// access to out BufferView. This should go...
139         BufferView * bv() const;
140
141         /// access to individual paragraphs
142         Paragraph & getPar(par_type par) const;
143         // Returns the current font and depth as a message.
144         std::string LyXText::currentState(LCursor & cur);
145
146         /** returns an iterator pointing to the row near the specified
147           * y-coordinate (relative to the whole text). y is set to the
148           * real beginning of this row
149           */
150         Row const & getRowNearY(int y, par_type & pit) const;
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         pos_type getColumnNearX(par_type pit,
156                 Row const & row, int & x, bool & boundary) const;
157
158         /** Find the word under \c from in the relative location
159          *  defined by \c word_location.
160          *  @param from return here the start of the word
161          *  @param to return here the end of the word
162          */
163         void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
164         /// just selects the word the cursor is in
165         void selectWord(LCursor & cur, lyx::word_location loc);
166
167         /// accept selected change
168         void acceptChange(LCursor & cur);
169         /// reject selected change
170         void rejectChange(LCursor & cur);
171
172         /// returns true if par was empty and was removed
173         bool setCursor(LCursor & cur, par_type par, pos_type pos,
174                        bool setfont = true, bool boundary = false);
175         ///
176         void setCursor(CursorSlice &, par_type par,
177                        pos_type pos, bool boundary = false);
178         ///
179         void setCursorIntern(LCursor & cur, par_type par,
180                  pos_type pos, bool setfont = true, bool boundary = false);
181         ///
182         void setCurrentFont(LCursor & cur);
183
184         ///
185         void recUndo(par_type first, par_type last) const;
186         ///
187         void recUndo(par_type first) const;
188         ///
189         void setCursorFromCoordinates(LCursor & cur, int x, int y);
190         ///
191         InsetBase * editXY(LCursor & cur, int x, int y) const;
192         ///
193         void cursorUp(LCursor & cur);
194         ///
195         void cursorDown(LCursor & cur);
196         ///
197         void cursorLeft(LCursor & cur);
198         ///
199         void cursorRight(LCursor & cur);
200         ///
201         void cursorLeftOneWord(LCursor & cur);
202         ///
203         void cursorRightOneWord(LCursor & cur);
204         ///
205         void cursorUpParagraph(LCursor & cur);
206         ///
207         void cursorDownParagraph(LCursor & cur);
208         ///
209         void cursorHome(LCursor & cur);
210         ///
211         void cursorEnd(LCursor & cur);
212         ///
213         void cursorPrevious(LCursor & cur);
214         ///
215         void cursorNext(LCursor & cur);
216         ///
217         void cursorTop(LCursor & cur);
218         ///
219         void cursorBottom(LCursor & cur);
220         ///
221         void Delete(LCursor & cur);
222         ///
223         void backspace(LCursor & cur);
224         ///
225         bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
226         ///
227         enum TextCase {
228                 ///
229                 text_lowercase = 0,
230                 ///
231                 text_capitalization = 1,
232                 ///
233                 text_uppercase = 2
234         };
235         /// Change the case of the word at cursor position.
236         void changeCase(LCursor & cur, TextCase action);
237
238         /** the DTP switches for paragraphs. LyX will store the top settings
239          always in the first physical paragraph, the bottom settings in the
240          last. When a paragraph is broken, the top settings rest, the bottom
241          settings are given to the new one.
242          */
243         void setParagraph(LCursor & cur,
244                           Spacing const & spacing,
245                           LyXAlignment align,
246                           std::string const & labelwidthstring,
247                           bool noindent);
248
249         /* these things are for search and replace */
250
251         /// needed to insert the selection
252         void insertStringAsLines(LCursor & cur, std::string const & str);
253         /// needed to insert the selection
254         void insertStringAsParagraphs(LCursor & cur, std::string const & str);
255
256         /// Find next inset of some specified type.
257         bool gotoNextInset(LCursor & cur,
258                 std::vector<InsetOld_code> const & codes,
259                 std::string const & contents = std::string());
260         ///
261         void gotoInset(LCursor & cur,
262                 std::vector<InsetOld_code> const & codes, bool same_content);
263         ///
264         void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
265
266         /// current text width
267         int width() const;
268
269         /// current text heigth
270         int height() const;
271
272         /// updates all counters
273         void updateCounters();
274         /// Returns an inset if inset was hit, or 0 if not.
275         InsetBase * checkInsetHit(int x, int y) const;
276
277         ///
278         int singleWidth(Paragraph const & par, pos_type pos) const;
279         ///
280         int singleWidth(Paragraph const & par,
281                 pos_type pos, char c, LyXFont const & Font) const;
282
283         /// return the color of the canvas
284         LColor_color backgroundColor() const;
285
286         /**
287          * Returns the left beginning of the text.
288          * This information cannot be taken from the layout object, because
289          * in LaTeX the beginning of the text fits in some cases
290          * (for example sections) exactly the label-width.
291          */
292         int leftMargin(par_type pit, pos_type pos) const;
293         int leftMargin(par_type pit) const;
294         ///
295         int rightMargin(Paragraph const & par) const;
296
297         /** this calculates the specified parameters. needed when setting
298          * the cursor and when creating a visible row */
299         RowMetrics computeRowMetrics(par_type pit, Row const & row) const;
300
301         /// access to our paragraphs
302         ParagraphList & paragraphs() const;
303         /// return true if this is the main text
304         bool isMainText() const;
305
306         /// return first row of text
307         Row const & firstRow() const;
308
309         /// is this row the last in the text?
310         bool isLastRow(par_type pit, Row const & row) const;
311         /// is this row the first in the text?
312         bool isFirstRow(par_type pit, Row const & row) const;
313
314         ///
315         double spacing(Paragraph const & par) const;
316         /// make a suggestion for a label
317         std::string getPossibleLabel(LCursor & cur) const;
318         /// is this paragraph right-to-left?
319         bool isRTL(Paragraph const & par) const;
320         ///
321         bool checkAndActivateInset(LCursor & cur, bool front);
322
323         ///
324         void write(Buffer const & buf, std::ostream & os) const;
325         /// returns whether we've seen our usual 'end' marker
326         bool read(Buffer const & buf, LyXLex & lex);
327
328         ///
329         int ascent() const;
330         ///
331         int descent() const;
332         ///
333         int cursorX(CursorSlice const & cursor) const;
334         ///
335         int cursorY(CursorSlice const & cursor) const;
336
337         ///
338         friend class LyXScreen;
339
340 public:
341         ///
342         unsigned int width_;
343         ///
344         int maxwidth_;
345         ///
346         int height_;
347         /// the current font settings
348         LyXFont current_font;
349         /// the current font
350         LyXFont real_current_font;
351         /// our buffer's default layout font
352         LyXFont defaultfont_;
353         ///
354         int background_color_;
355
356         /// only the top-level LyXText has this non-zero
357         BufferView * bv_owner;
358
359         ///
360         mutable Bidi bidi;
361         ///
362         ParagraphList pars_;
363
364         /// absolute document pixel coordinates of this LyXText
365         mutable int xo_;
366         mutable int yo_;
367
368         /// our 'outermost' Font
369         LyXFont font_;
370
371 private:
372         /// return past-the-last paragraph influenced by a layout
373         /// change on pit
374         par_type undoSpan(par_type pit);
375
376         /// rebreaks the given par
377         void redoParagraphInternal(par_type pit);
378         /// used in setlayout
379         void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
380
381         /// Calculate and set the height of the row
382         void setHeightOfRow(par_type, Row & row);
383
384         // fix the cursor `cur' after a characters has been deleted at `where'
385         // position. Called by deleteEmptyParagraphMechanism
386         void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
387
388         /// delete double space or empty paragraphs around old cursor
389         bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
390
391         ///
392         void setCounter(Buffer const &, par_type pit);
393         ///
394         void deleteWordForward(LCursor & cur);
395         ///
396         void deleteWordBackward(LCursor & cur);
397         ///
398         void deleteLineForward(LCursor & cur);
399
400         /// sets row.end to the pos value *after* which a row should break.
401         /// for example, the pos after which isNewLine(pos) == true
402         void rowBreakPoint(par_type pit, Row & row) const;
403         /// sets row.width to the minimum space a row needs on the screen in pixel
404         void setRowWidth(par_type pit, Row & row) const;
405         /// the minimum space a manual label needs on the screen in pixels
406         int labelFill(Paragraph const & par, Row const & row) const;
407         /// FIXME
408         int labelEnd(par_type pit) const;
409
410         ///
411         void charInserted();
412         /// set 'number' font property
413         void number(LCursor & cur);
414 };
415
416 /// return the default height of a row in pixels, considering font zoom
417 int defaultRowHeight();
418
419 ///
420 std::string expandLabel(LyXTextClass const & textclass,
421                 LyXLayout_ptr const & layout, bool appendix);
422
423
424 #endif // LYXTEXT_H