2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 Matthias Ettrich
9 *======================================================*/
18 #include "definitions.h"
23 #include "lyxcursor.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, int pos);
68 void SetCharFont(LyXParagraph *par, int pos, LyXFont font);
70 /// returns a pointer to the very first LyXParagraph
71 LyXParagraph *FirstParagraph();
73 /// what you expect when pressing <enter> at cursor position
74 void BreakParagraph(char keep_layout = 0);
76 /** set layout over selection and make a total rebreak of
79 void SetLayout(char layout);
82 void MakeFontEntriesLayoutSpecific(LyXParagraph *par);
84 /** increment depth over selection and make a total rebreak of those
89 /** decrement depth over selection and make a total rebreak of those
93 /** Get the depth at current cursor position
95 int GetDepth() { return cursor.par->GetDepth(); }
97 /** set font over selection and make a total rebreak of those
99 toggleall defaults to false.
101 void SetFont(LyXFont font, bool toggleall=false);
103 /** deletes and inserts again all paragaphs between the cursor
104 and the specified par .The Cursor is needed to set the refreshing
106 This function is needed after SetLayout and SetFont etc.
108 void RedoParagraphs(LyXCursor cursor, LyXParagraph *end_par);
110 void RedoParagraph();
113 void ToggleFree(LyXFont font,bool toggleall=false);
115 /** recalculates the heights of all previous rows of the
116 specified paragraph. needed, if the last characters font
119 void RedoHeightOfParagraph(LyXCursor cursor);
121 /** forces the redrawing of a paragraph. Needed when manipulating a
124 void RedoDrawingOfParagraph(LyXCursor cursor);
126 /** insert a character, moves all the following breaks in the
127 same Paragraph one to the right and make a little rebreak
129 void InsertChar(char c);
131 void InsertInset(Inset *inset);
133 /// completes the insertion with a full rebreak
136 /// may be important for the menu
137 char* GetLayout(int row);
139 LyXParagraph::footnote_flag GetFootnoteFlag(int 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, int 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.
188 /* the selection cursor */
195 LyXCursor sel_cursor;
197 LyXCursor sel_start_cursor;
199 LyXCursor sel_end_cursor;
200 /// needed for the toggling
201 LyXCursor last_sel_cursor;
203 LyXCursor toggle_cursor;
205 LyXCursor toggle_end_cursor;
207 /// need the selection cursor:
210 void ClearSelection();
212 /// just selects the word the cursor is in
215 /** 'selects" the next word, where the cursor is not in
216 and returns this word as string. THe cursor will be moved
217 to the beginning of this word.
218 With SelectSelectedWord can this be highlighted really
220 char* SelectNextWord(float &value);
222 void SelectSelectedWord();
224 void SetCursor(LyXParagraph *par, int pos);
226 void SetCursorIntern(LyXParagraph *par, int pos);
228 void SetCursorFromCoordinates(int x, long y);
238 void CursorLeftOneWord();
240 void CursorRightOneWord();
242 void CursorUpParagraph();
244 void CursorDownParagraph();
260 void DeleteWordForward();
262 void DeleteWordBackward();
264 void DeleteLineForward();
266 int SelectWordWhenUnderCursor();
267 /// Change the case of the word at cursor position
268 /** action is 0 for lower case, 1 for capitalization and 2 for
271 void ChangeWordCase(int action);
273 /** returns a printed row in a pixmap. The y value is needed to
274 decide, wether it is selected text or not. This is a strange
277 void GetVisibleRow(LyXScreen &scr, int offset,
278 Row *row_ptr, long y);
282 void ToggleFootnote();
286 void OpenFootnotes();
290 void CloseFootnotes();
292 void CloseFootnote();
294 /** turn the selection into a new environment. If there is no
295 selection, create an empty environment
297 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
299 void MeltFootnoteEnvironment();
301 void CutSelection(bool = true);
303 void CopySelection();
305 void PasteSelection();
307 void copyEnvironmentType();
309 void pasteEnvironmentType();
311 void InsertFootnote();
313 void InsertMarginpar();
317 void InsertTabular();
319 /** the DTP switches for paragraphs. LyX will store the top settings
320 always in the first physical paragraph, the bottom settings in the
321 last. When a paragraph is broken, the top settings rest, the bottom
322 settings are given to the new one. So I can make shure, they do not
323 duplicate themself (and you cannnot make dirty things with them! )
325 void SetParagraph(bool line_top, bool line_bottom,
326 bool pagebreak_top, bool pagebreak_bottom,
327 VSpace space_top, VSpace space_bottom,
329 LString labelwidthstring,
331 void SetParagraphExtraOpt(int type,
334 int alignment, bool hfill,
335 bool start_minipage);
337 /* these things are for search and replace */
339 /** returns true if the specified string is at the specified
342 bool IsStringInText(LyXParagraph *par, int pos, char const* string);
344 /** sets the selection over the number of characters of string,
347 void SetSelectionOverString(char const* string);
349 /** simple replacing. The font of the first selected character
352 void ReplaceSelectionWithString(char const* string);
354 /** if the string can be found: return true and set the cursor to
356 bool SearchForward(char const* string);
357 bool SearchBackward(char const* string);
359 /// needed to insert the selection
360 void InsertStringA(char* string);
361 /// needed to insert the selection
362 void InsertStringB(char* string);
364 /// usefull when texing from within LyX
365 bool GotoNextError();
367 /// just another feature :)
370 /** needed to switch between different classes this works
371 for a list of paragraphs beginning with the specified par
372 return value is the number of wrong conversions
374 int SwitchLayoutsBetweenClasses(char class1, char class2, LyXParagraph *par);
376 /* for the greater insets */
378 /// returns 0 if inset wasn't found
379 int UpdateInset(Inset* inset);
381 void CheckParagraph(LyXParagraph* par, int pos);
383 /* table stuff -- begin*/
385 /** all table features of the text-class are put together in
386 this function. Possible values of feature are defined in table.h
388 void TableFeatures(int feature,LString val);
390 void TableFeatures(int feature);
392 int NumberOfCell(LyXParagraph *par, int pos);
394 /** pos points at the beginning of the next cell (if there is one)
396 int WidthOfCell(LyXParagraph *par, int &pos);
398 void InsertCharInTable(char c);
400 void BackspaceInTable();
402 void CheckParagraphInTable(LyXParagraph* par, int pos);
404 char HitInTable(Row* row, int x);
406 bool MouseHitInTable(int x, long y);
407 /* table stuff -- end*/
409 LyXParagraph* GetParFromID(int id);
412 /// returns false if no undo possible
414 /// returns false if no redo possible
416 /// used by TextUndo/TextRedo
417 bool TextHandleUndo(Undo* undo);
418 /// makes sure the next operation will be stored
420 /// this is dangerous and for internal use only
422 /// this is dangerous and for internal use only
424 /// the flag used by FinishUndo();
429 void SetUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
431 void SetRedo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
433 Undo *CreateUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
434 /// for external use in lyx_cb.C
435 void SetCursorParUndo();
437 void CursorLeftIntern();
439 void CursorRightIntern();
441 void RemoveTableRow(LyXCursor *cursor);
443 bool IsEmptyTableRow(LyXCursor *cursor);
445 bool IsEmptyTableCell();
447 void toggleAppendix();
455 /** Copybuffer for copy environment type
456 Asger has learned that this should be a buffer-property instead
457 Lgb has learned that 'char' is a lousy type for non-characters
461 /// the currentrow is needed to access rows faster*/
462 Row* currentrow; /* pointer to the current row */
463 /// position in the text
465 /// width of the paper
466 unsigned short paperwidth;
468 /** inserts a new row behind the specified row, increments
469 * the touched counters */
470 void InsertRow(Row *row, LyXParagraph *par, int pos );
472 /** removes the row and reset the touched counters */
473 void RemoveRow(Row *row);
475 /** remove all following rows of the paragraph of the specified row. */
476 void RemoveParagraph(Row *row);
478 /** insert the specified paragraph behind the specified row */
479 void InsertParagraph(LyXParagraph *par, Row *row);
481 /** appends the implizit specified paragraph behind the specified row,
482 * start at the implizit given position */
483 void AppendParagraph(Row *row);
486 void BreakAgain(Row *row);
488 void BreakAgainOneRow(Row *row);
490 void SetHeightOfRow(Row *row_ptr); /* calculate and set the height
493 /** this calculates the specified parameters. needed when setting
494 * the cursor and when creating a visible row */
495 void PrepareToPrint(Row *row, float &x, float &fill_separator,
496 float &fill_hfill, float &fill_label_hfill);
498 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
500 /** Updates all counters starting BEHIND the row. Changed paragraphs
501 * with a dynamic left margin will be rebroken. */
502 void UpdateCounters(Row *row);
504 void SetCounter(LyXParagraph *par);
507 * some low level functions
511 int SingleWidth(LyXParagraph *par, int pos);
513 int SingleWidth(LyXParagraph *par, int pos, char c);
515 void Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x);
516 /// get the next breakpoint in a given paragraph
517 int NextBreakPoint(Row* row, int width);
518 /// returns the minimum space a row needs on the screen in pixel
519 int Fill(Row *row, int paperwidth);
521 /** returns the minimum space a manual label needs on the
523 int LabelFill(Row *row);
526 int BeginningOfMainBody(LyXParagraph *par);
528 /** Returns the left beginning of the text.
529 This information cannot be taken from the layouts-objekt, because
530 in LaTeX the beginning of the text fits in some cases
531 (for example sections) exactly the label-width.
533 int LeftMargin(Row *row);
535 int RightMargin(Row *row);
537 int LabelEnd (Row *row);
539 /** returns the number of separators in the specified row.
540 The separator on the very last column doesnt count
542 int NumberOfSeparators(Row *row);
544 /** returns the number of hfills in the specified row. The
545 LyX-Hfill is a LaTeX \hfill so that the hfills at the
546 beginning and at the end were ignored. This is {\em MUCH}
547 more usefull than not to ignore!
549 int NumberOfHfills(Row *row);
551 /// like NumberOfHfills, but only those in the manual label!
552 int NumberOfLabelHfills(Row *row);
554 /** returns true, if a expansion is needed. Rules are given by
557 bool HfillExpansion(Row *row_ptr, int pos);
559 /** returns the paragraph position of the last character in the
562 int RowLast(Row *row);