2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ====================================================== */
22 #include "lyxcursor.h"
23 #include "lyxparagraph.h"
30 This class holds the mapping between buffer paragraphs and screen rows.
43 NEED_VERY_LITTLE_REFRESH
46 /// points to Buffer.params
47 BufferParams * parameters;
54 /// the current font settings
57 LyXFont real_current_font;
60 LyXText(int paperwidth, Buffer *);
66 LyXFont GetFont(LyXParagraph * par,
67 LyXParagraph::size_type pos);
69 void SetCharFont(LyXParagraph * par,
70 LyXParagraph::size_type pos,
72 /// returns a pointer to the very first LyXParagraph
73 LyXParagraph * FirstParagraph();
75 /// what you expect when pressing <enter> at cursor position
76 void BreakParagraph(char keep_layout = 0);
78 /** set layout over selection and make a total rebreak of
81 void SetLayout(char layout);
84 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
86 /** increment depth over selection and make a total rebreak of those
91 /** decrement depth over selection and make a total rebreak of those
95 /** Get the depth at current cursor position
97 int GetDepth() { return cursor.par->GetDepth(); }
99 /** set font over selection and make a total rebreak of those
101 toggleall defaults to false.
103 void SetFont(LyXFont font, bool toggleall = false);
105 /** deletes and inserts again all paragaphs between the cursor
106 and the specified par .The Cursor is needed to set the refreshing
108 This function is needed after SetLayout and SetFont etc.
110 void RedoParagraphs(LyXCursor cursor, LyXParagraph * end_par);
112 void RedoParagraph();
115 void ToggleFree(LyXFont font, bool toggleall = false);
117 /** recalculates the heights of all previous rows of the
118 specified paragraph. needed, if the last characters font
121 void RedoHeightOfParagraph(LyXCursor cursor);
123 /** forces the redrawing of a paragraph. Needed when manipulating a
126 void RedoDrawingOfParagraph(LyXCursor cursor);
128 /** insert a character, moves all the following breaks in the
129 same Paragraph one to the right and make a little rebreak
131 void InsertChar(char c);
133 void InsertInset(Inset * inset);
135 /// completes the insertion with a full rebreak
139 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
141 Row * need_break_row;
155 /** wether the screen needs a refresh,
156 starting with refresh_y
160 /** returns a pointer to the row near the specified y-coordinate
161 (relative to the whole text). y is set to the real beginning
164 Row * GetRowNearY(long & y);
166 /** returns the column near the specified x-coordinate of the row
167 x is set to the real beginning of this column
169 int GetColumnNearX(Row * row, int & x);
171 /** returns a pointer to a specified row. y is set to the beginning
174 Row * GetRow(LyXParagraph * par,
175 LyXParagraph::size_type pos, long & y);
176 /** returns the height of a default row, needed for scrollbar
181 Later this variable has to be removed. There should be now internal
182 cursor in a text (and thus not in a buffer). By keeping this it is
183 (I think) impossible to have several views with the same buffer, but
184 the cursor placed at different places.
186 Since the LyXText now has been moved from Buffer to BufferView
187 it should not be absolutely needed to move the cursor...
191 /* the selection cursor */
198 LyXCursor sel_cursor;
200 LyXCursor sel_start_cursor;
202 LyXCursor sel_end_cursor;
203 /// needed for the toggling
204 LyXCursor last_sel_cursor;
206 LyXCursor toggle_cursor;
208 LyXCursor toggle_end_cursor;
210 /// need the selection cursor:
213 void ClearSelection();
215 /// just selects the word the cursor is in
218 /** 'selects" the next word, where the cursor is not in
219 and returns this word as string. THe cursor will be moved
220 to the beginning of this word.
221 With SelectSelectedWord can this be highlighted really
223 char * SelectNextWord(float & value);
225 void SelectSelectedWord();
227 void SetCursor(LyXParagraph * par,
228 LyXParagraph::size_type pos);
230 void SetCursorIntern(LyXParagraph * par,
231 LyXParagraph::size_type pos);
233 void SetCursorFromCoordinates(int x, long y);
243 void CursorLeftOneWord();
245 void CursorRightOneWord();
247 void CursorUpParagraph();
249 void CursorDownParagraph();
265 void DeleteWordForward();
267 void DeleteWordBackward();
269 void DeleteLineForward();
271 int SelectWordWhenUnderCursor();
275 text_capitalization = 1,
278 /// Change the case of the word at cursor position.
279 void ChangeWordCase(TextCase action);
281 /** returns a printed row in a pixmap. The y value is needed to
282 decide, wether it is selected text or not. This is a strange
285 void GetVisibleRow(LyXScreen & scr, int offset,
286 Row * row_ptr, long y);
290 void ToggleFootnote();
294 void OpenFootnotes();
298 void CloseFootnotes();
300 void CloseFootnote();
302 /** turn the selection into a new environment. If there is no
303 selection, create an empty environment
305 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
307 void MeltFootnoteEnvironment();
309 void CutSelection(bool = true);
311 void CopySelection();
313 void PasteSelection();
315 void copyEnvironmentType();
317 void pasteEnvironmentType();
319 void InsertFootnote();
321 void InsertMarginpar();
325 void InsertTabular();
327 /** the DTP switches for paragraphs. LyX will store the top settings
328 always in the first physical paragraph, the bottom settings in the
329 last. When a paragraph is broken, the top settings rest, the bottom
330 settings are given to the new one. So I can make shure, they do not
331 duplicate themself (and you cannnot make dirty things with them! )
333 void SetParagraph(bool line_top, bool line_bottom,
334 bool pagebreak_top, bool pagebreak_bottom,
335 VSpace space_top, VSpace space_bottom,
337 string labelwidthstring,
339 void SetParagraphExtraOpt(int type,
342 int alignment, bool hfill,
343 bool start_minipage);
345 /* these things are for search and replace */
347 /** returns true if the specified string is at the specified
350 bool IsStringInText(LyXParagraph * par,
351 LyXParagraph::size_type pos,
353 /** sets the selection over the number of characters of string,
356 void SetSelectionOverString(char const * str);
358 /** simple replacing. The font of the first selected character
361 void ReplaceSelectionWithString(char const * string);
363 /** if the string can be found: return true and set the cursor to
365 bool SearchForward(char const * string);
366 bool SearchBackward(char const * string);
368 /// needed to insert the selection
369 void InsertStringA(LyXParagraph::TextContainer const & text);
370 /// needed to insert the selection
371 void InsertStringB(LyXParagraph::TextContainer const & text);
372 /// needed to insert the selection
373 void InsertStringA(char const * string);
374 /// needed to insert the selection
375 void InsertStringB(char const * string);
377 /// usefull when texing from within LyX
378 bool GotoNextError();
380 /// just another feature :)
383 /** needed to switch between different classes this works
384 for a list of paragraphs beginning with the specified par
385 return value is the number of wrong conversions
387 int SwitchLayoutsBetweenClasses(char class1, char class2,
390 /* for the greater insets */
392 /// returns 0 if inset wasn't found
393 int UpdateInset(Inset * inset);
395 void CheckParagraph(LyXParagraph * par,
396 LyXParagraph::size_type pos);
398 int NumberOfCell(LyXParagraph * par,
399 LyXParagraph::size_type pos);
400 /* table stuff -- begin*/
402 /** all table features of the text-class are put together in
403 this function. Possible values of feature are defined in table.h
405 void TableFeatures(int feature, string val);
407 void TableFeatures(int feature);
409 /** pos points at the beginning of the next cell (if there is one)
411 int WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos);
413 void CheckParagraphInTable(LyXParagraph * par,
414 LyXParagraph::size_type pos);
416 void InsertCharInTable(char c);
418 void BackspaceInTable();
420 bool HitInTable(Row * row, int x);
422 bool MouseHitInTable(int x, long y);
423 /* table stuff -- end*/
425 LyXParagraph * GetParFromID(int id);
428 /// returns false if no undo possible
430 /// returns false if no redo possible
432 /// used by TextUndo/TextRedo
433 bool TextHandleUndo(Undo * undo);
434 /// makes sure the next operation will be stored
436 /// this is dangerous and for internal use only
438 /// this is dangerous and for internal use only
440 /// the flag used by FinishUndo();
445 void SetUndo(Undo::undo_kind kind, LyXParagraph * before,
448 void SetRedo(Undo::undo_kind kind, LyXParagraph * before,
451 Undo * CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
453 /// for external use in lyx_cb.C
454 void SetCursorParUndo();
456 void CursorLeftIntern();
458 void CursorRightIntern();
460 void RemoveTableRow(LyXCursor * cursor);
462 bool IsEmptyTableRow(LyXCursor * cursor) const;
464 bool IsEmptyTableCell() const;
466 void toggleAppendix();
468 unsigned short paperWidth() const { return paperwidth; }
471 /// width of the paper
472 unsigned short paperwidth;
479 /** Copybuffer for copy environment type
480 Asger has learned that this should be a buffer-property instead
481 Lgb has learned that 'char' is a lousy type for non-characters
485 /// the currentrow is needed to access rows faster*/
486 Row * currentrow; /* pointer to the current row */
487 /// position in the text
490 /** inserts a new row behind the specified row, increments
491 * the touched counters */
492 void InsertRow(Row * row, LyXParagraph * par,
493 LyXParagraph::size_type pos );
494 /** removes the row and reset the touched counters */
495 void RemoveRow(Row * row);
497 /** remove all following rows of the paragraph of the specified row. */
498 void RemoveParagraph(Row * row);
500 /** insert the specified paragraph behind the specified row */
501 void InsertParagraph(LyXParagraph * par, Row * row);
503 /** appends the implizit specified paragraph behind the specified row,
504 * start at the implizit given position */
505 void AppendParagraph(Row * row);
508 void BreakAgain(Row * row);
510 void BreakAgainOneRow(Row * row);
512 void SetHeightOfRow(Row * row_ptr); /* calculate and set the height
515 /** this calculates the specified parameters. needed when setting
516 * the cursor and when creating a visible row */
517 void PrepareToPrint(Row * row, float & x, float & fill_separator,
518 float & fill_hfill, float & fill_label_hfill);
520 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
522 /** Updates all counters starting BEHIND the row. Changed paragraphs
523 * with a dynamic left margin will be rebroken. */
524 void UpdateCounters(Row * row);
526 void SetCounter(LyXParagraph * par);
529 * some low level functions
533 int SingleWidth(LyXParagraph * par,
534 LyXParagraph::size_type pos);
536 int SingleWidth(LyXParagraph * par,
537 LyXParagraph::size_type pos, char c);
539 void Draw(Row * row, LyXParagraph::size_type & pos,
541 int offset, float & x);
542 /// get the next breakpoint in a given paragraph
543 LyXParagraph::size_type NextBreakPoint(Row * row,
545 /// returns the minimum space a row needs on the screen in pixel
546 int Fill(Row * row, int paperwidth);
548 /** returns the minimum space a manual label needs on the
550 int LabelFill(Row * row);
553 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
554 /** Returns the left beginning of the text.
555 This information cannot be taken from the layouts-objekt, because
556 in LaTeX the beginning of the text fits in some cases
557 (for example sections) exactly the label-width.
559 int LeftMargin(Row * row);
561 int RightMargin(Row * row);
563 int LabelEnd (Row * row);
565 /** returns the number of separators in the specified row.
566 The separator on the very last column doesnt count
568 int NumberOfSeparators(Row * row);
570 /** returns the number of hfills in the specified row. The
571 LyX-Hfill is a LaTeX \hfill so that the hfills at the
572 beginning and at the end were ignored. This is {\em MUCH}
573 more usefull than not to ignore!
575 int NumberOfHfills(Row * row);
577 /// like NumberOfHfills, but only those in the manual label!
578 int NumberOfLabelHfills(Row * row);
580 /** returns true, if a expansion is needed. Rules are given by
583 bool HfillExpansion(Row * row_ptr,
584 LyXParagraph::size_type pos);
585 /** returns the paragraph position of the last character in the
588 LyXParagraph::size_type RowLast(Row * row);