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"
20 #include "dimension.h"
23 #include "lyxlayout_ptr_fwd.h"
24 #include "ParagraphList_fwd.h"
47 /// This class encapsulates the main text data and operations in LyX
51 typedef lyx::pos_type pos_type
;
53 typedef lyx::pit_type pit_type
;
56 explicit LyXText(BufferView
*);
58 void init(BufferView
*);
61 LyXFont
getFont(Paragraph
const & par
, pos_type pos
) const;
63 void applyOuterFont(LyXFont
&) const;
65 LyXFont
getLayoutFont(pit_type pit
) const;
67 LyXFont
getLabelFont(Paragraph
const & par
) const;
69 void setCharFont(pit_type pit
, pos_type pos
, LyXFont
const & font
);
71 void setCharFont(pit_type pit
, pos_type pos
, LyXFont
const & font
,
74 /// what you expect when pressing <enter> at cursor position
75 void breakParagraph(LCursor
& cur
, bool keep_layout
= false);
77 /// set layout over selection
78 pit_type
setLayout(pit_type start
, pit_type end
,
79 std::string
const & layout
);
81 void setLayout(LCursor
& cur
, std::string
const & layout
);
83 /// what type of depth change to make
88 /// Increase or decrease the nesting depth of the selected paragraph(s)
89 void changeDepth(LCursor
& cur
, DEPTH_CHANGE type
);
91 /// Returns whether something would be changed by changeDepth
92 bool changeDepthAllowed(LCursor
& cur
, DEPTH_CHANGE type
) const;
94 /// Set font over selection paragraphs and rebreak.
95 void setFont(LCursor
& cur
, LyXFont
const &, bool toggleall
= false);
97 /// rebreaks the given par
98 bool redoParagraph(pit_type pit
);
100 /// returns pos in given par at given x coord
101 pos_type
x2pos(pit_type pit
, int row
, int x
) const;
102 int pos2x(pit_type pit
, pos_type pos
) const;
105 void toggleFree(LCursor
& cur
, LyXFont
const &, bool toggleall
= false);
108 std::string
getStringToIndex(LCursor
const & cur
);
110 /// insert a character at cursor position
111 void insertChar(LCursor
& cur
, char c
);
112 /// insert an inset at cursor position
113 void insertInset(LCursor
& cur
, InsetBase
* inset
);
115 /// compute text metrics
116 void metrics(MetricsInfo
& mi
, Dimension
& dim
);
117 /// draw text (only used for insets)
118 void draw(PainterInfo
& pi
, int x
, int y
) const;
119 /// draw textselection
120 void drawSelection(PainterInfo
& pi
, int x
, int y
) const;
122 /// try to handle that request
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;
128 /// access to out BufferView. This should go...
129 // BufferView * bv();
130 /// access to out BufferView. This should go...
131 BufferView
* bv() const;
133 /// access to individual paragraphs
134 Paragraph
& getPar(pit_type par
) const;
135 // Returns the current font and depth as a message.
136 std::string
LyXText::currentState(LCursor
& cur
);
138 /** returns row near the specified
139 * y-coordinate in given paragraph (relative to the screen).
141 Row
const & getRowNearY(int y
, pit_type pit
) const;
142 pit_type
getPitNearY(int y
) const;
144 /** returns the column near the specified x-coordinate of the row
145 x is set to the real beginning of this column
147 pos_type
getColumnNearX(pit_type pit
,
148 Row
const & row
, int & x
, bool & boundary
) const;
150 /** Find the word under \c from in the relative location
151 * defined by \c word_location.
152 * @param from return here the start of the word
153 * @param to return here the end of the word
155 void getWord(CursorSlice
& from
, CursorSlice
& to
, lyx::word_location
const);
156 /// just selects the word the cursor is in
157 void selectWord(LCursor
& cur
, lyx::word_location loc
);
159 /// accept selected change
160 void acceptChange(LCursor
& cur
);
161 /// reject selected change
162 void rejectChange(LCursor
& cur
);
164 /// returns true if par was empty and was removed
165 bool setCursor(LCursor
& cur
, pit_type par
, pos_type pos
,
166 bool setfont
= true, bool boundary
= false);
168 void setCursor(CursorSlice
&, pit_type par
,
169 pos_type pos
, bool boundary
= false);
171 void setCursorIntern(LCursor
& cur
, pit_type par
,
172 pos_type pos
, bool setfont
= true, bool boundary
= false);
174 void setCurrentFont(LCursor
& cur
);
177 void recUndo(pit_type first
, pit_type last
) const;
179 void recUndo(pit_type first
) const;
181 void setCursorFromCoordinates(LCursor
& cur
, int x
, int y
);
183 InsetBase
* editXY(LCursor
& cur
, int x
, int y
) const;
184 /// Move cursor one line up.
186 * Returns true if an update is needed after the move.
188 bool cursorUp(LCursor
& cur
);
189 /// Move cursor one line down.
191 * Returns true if an update is needed after the move.
193 bool cursorDown(LCursor
& cur
);
194 /// Move cursor one position left
196 * Returns true if an update is needed after the move.
198 bool cursorLeft(LCursor
& cur
);
199 /// Move cursor one position right
201 * Returns true if an update is needed after the move.
203 bool cursorRight(LCursor
& cur
);
205 bool cursorLeftOneWord(LCursor
& cur
);
207 bool cursorRightOneWord(LCursor
& cur
);
209 bool cursorUpParagraph(LCursor
& cur
);
211 bool cursorDownParagraph(LCursor
& cur
);
213 void cursorHome(LCursor
& cur
);
215 void cursorEnd(LCursor
& cur
);
217 bool cursorPrevious(LCursor
& cur
);
219 bool cursorNext(LCursor
& cur
);
221 void cursorTop(LCursor
& cur
);
223 void cursorBottom(LCursor
& cur
);
225 void Delete(LCursor
& cur
);
227 void backspace(LCursor
& cur
);
229 bool selectWordWhenUnderCursor(LCursor
& cur
, lyx::word_location
);
235 text_capitalization
= 1,
239 /// Change the case of the word at cursor position.
240 void changeCase(LCursor
& cur
, TextCase action
);
242 /** the DTP switches for paragraphs. LyX will store the top settings
243 always in the first physical paragraph, the bottom settings in the
244 last. When a paragraph is broken, the top settings rest, the bottom
245 settings are given to the new one.
247 void setParagraph(LCursor
& cur
,
248 Spacing
const & spacing
,
250 std::string
const & labelwidthstring
,
253 /* these things are for search and replace */
255 /// needed to insert the selection
256 void insertStringAsLines(LCursor
& cur
, std::string
const & str
);
257 /// needed to insert the selection
258 void insertStringAsParagraphs(LCursor
& cur
, std::string
const & str
);
260 /// current text width
263 /// current text heigth
266 /// Returns an inset if inset was hit, or 0 if not.
267 InsetBase
* checkInsetHit(int x
, int y
) const;
270 int singleWidth(Paragraph
const & par
, pos_type pos
) const;
272 int singleWidth(Paragraph
const & par
,
273 pos_type pos
, char c
, LyXFont
const & Font
) const;
275 /// return the color of the canvas
276 LColor_color
backgroundColor() const;
279 * Returns the left beginning of the text.
280 * This information cannot be taken from the layout object, because
281 * in LaTeX the beginning of the text fits in some cases
282 * (for example sections) exactly the label-width.
284 int leftMargin(pit_type pit
, pos_type pos
) const;
285 int leftMargin(pit_type pit
) const;
287 int rightMargin(Paragraph
const & par
) const;
289 /** this calculates the specified parameters. needed when setting
290 * the cursor and when creating a visible row */
291 RowMetrics
computeRowMetrics(pit_type pit
, Row
const & row
) const;
293 /// access to our paragraphs
294 ParagraphList
& paragraphs() const;
295 /// return true if this is the main text
296 bool isMainText() const;
298 /// return first row of text
299 Row
const & firstRow() const;
301 /// is this row the last in the text?
302 bool isLastRow(pit_type pit
, Row
const & row
) const;
303 /// is this row the first in the text?
304 bool isFirstRow(pit_type pit
, Row
const & row
) const;
307 double spacing(Paragraph
const & par
) const;
308 /// make a suggestion for a label
309 std::string
getPossibleLabel(LCursor
& cur
) const;
310 /// is this paragraph right-to-left?
311 bool isRTL(Paragraph
const & par
) const;
313 bool checkAndActivateInset(LCursor
& cur
, bool front
);
316 void write(Buffer
const & buf
, std::ostream
& os
) const;
317 /// returns whether we've seen our usual 'end' marker
318 bool read(Buffer
const & buf
, LyXLex
& lex
);
325 int cursorX(CursorSlice
const & cursor
) const;
327 int cursorY(CursorSlice
const & cursor
) const;
330 friend class LyXScreen
;
337 /// the current font settings
338 LyXFont current_font
;
340 LyXFont real_current_font
;
341 /// our buffer's default layout font. This is textclass specific
342 LyXFont defaultfont_
;
344 int background_color_
;
346 /// only the top-level LyXText has this non-zero
347 BufferView
* bv_owner
;
354 /// our 'outermost' font. This is handed down from the surrounding
355 // inset through the pi/mi parameter (pi.base.font)
361 /// return past-the-last paragraph influenced by a layout
363 pit_type
undoSpan(pit_type pit
);
365 /// used in setlayout
366 void makeFontEntriesLayoutSpecific(BufferParams
const &, Paragraph
& par
);
368 /// Calculate and set the height of the row
369 void setHeightOfRow(pit_type
, Row
& row
);
371 // fix the cursor `cur' after a characters has been deleted at `where'
372 // position. Called by deleteEmptyParagraphMechanism
373 void fixCursorAfterDelete(CursorSlice
& cur
, CursorSlice
const & where
);
375 /// delete double space or empty paragraphs around old cursor
376 bool deleteEmptyParagraphMechanism(LCursor
& cur
, LCursor
const & old
);
379 void deleteWordForward(LCursor
& cur
);
381 void deleteWordBackward(LCursor
& cur
);
383 void deleteLineForward(LCursor
& cur
);
385 /// sets row.end to the pos value *after* which a row should break.
386 /// for example, the pos after which isNewLine(pos) == true
387 void rowBreakPoint(pit_type pit
, Row
& row
) const;
388 /// sets row.width to the minimum space a row needs on the screen in pixel
389 void setRowWidth(pit_type pit
, Row
& row
) const;
390 /// the minimum space a manual label needs on the screen in pixels
391 int labelFill(Paragraph
const & par
, Row
const & row
) const;
393 int labelEnd(pit_type pit
) const;
397 /// set 'number' font property
398 void number(LCursor
& cur
);
401 /// return the default height of a row in pixels, considering font zoom
402 int defaultRowHeight();