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 * ======================================================*/
19 #include "definitions.h"
24 #include "lyxcursor.h"
31 This class holds the mapping between buffer paragraphs and screen rows.
44 NEED_VERY_LITTLE_REFRESH
47 /// points to Buffer.params
48 BufferParams *parameters;
55 /// the current font settings
58 LyXFont real_current_font;
61 LyXText(int paperwidth, Buffer *);
67 LyXFont GetFont(LyXParagraph* par, int pos);
69 void SetCharFont(LyXParagraph *par, int pos, LyXFont font);
71 /// returns a pointer to the very first LyXParagraph
72 LyXParagraph *FirstParagraph();
74 /// what you expect when pressing <enter> at cursor position
75 void BreakParagraph(char keep_layout = 0);
77 /** set layout over selection and make a total rebreak of
80 void SetLayout(char layout);
83 void MakeFontEntriesLayoutSpecific(LyXParagraph *par);
85 /** increment depth over selection and make a total rebreak of those
90 /** decrement depth over selection and make a total rebreak of those
94 /** Get the depth at current cursor position
96 int GetDepth() { return cursor.par->GetDepth(); }
98 /** set font over selection and make a total rebreak of those
100 toggleall defaults to false.
102 void SetFont(LyXFont font, bool toggleall=false);
104 /** deletes and inserts again all paragaphs between the cursor
105 and the specified par .The Cursor is needed to set the refreshing
107 This function is needed after SetLayout and SetFont etc.
109 void RedoParagraphs(LyXCursor cursor, LyXParagraph *end_par);
111 void RedoParagraph();
114 void ToggleFree(LyXFont font,bool toggleall=false);
116 /** recalculates the heights of all previous rows of the
117 specified paragraph. needed, if the last characters font
120 void RedoHeightOfParagraph(LyXCursor cursor);
122 /** forces the redrawing of a paragraph. Needed when manipulating a
125 void RedoDrawingOfParagraph(LyXCursor cursor);
127 /** insert a character, moves all the following breaks in the
128 same Paragraph one to the right and make a little rebreak
130 void InsertChar(char c);
132 void InsertInset(Inset *inset);
134 /// completes the insertion with a full rebreak
137 /// may be important for the menu
138 char* GetLayout(int row);
140 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
156 /** wether the screen needs a refresh,
157 starting with refresh_y
161 /** returns a pointer to the row near the specified y-coordinate
162 (relative to the whole text). y is set to the real beginning
165 Row* GetRowNearY(long &y);
167 /** returns the column near the specified x-coordinate of the row
168 x is set to the real beginning of this column
170 int GetColumnNearX(Row *row, int& x);
172 /** returns a pointer to a specified row. y is set to the beginning
175 Row* GetRow(LyXParagraph *par, int pos, long &y);
177 /** returns the height of a default row, needed for scrollbar
182 Later this variable has to be removed. There should be now internal
183 cursor in a text (and thus not in a buffer). By keeping this it is
184 (I think) impossible to have several views with the same buffer, but
185 the cursor placed at different places.
189 /* the selection cursor */
196 LyXCursor sel_cursor;
198 LyXCursor sel_start_cursor;
200 LyXCursor sel_end_cursor;
201 /// needed for the toggling
202 LyXCursor last_sel_cursor;
204 LyXCursor toggle_cursor;
206 LyXCursor toggle_end_cursor;
208 /// need the selection cursor:
211 void ClearSelection();
213 /// just selects the word the cursor is in
216 /** 'selects" the next word, where the cursor is not in
217 and returns this word as string. THe cursor will be moved
218 to the beginning of this word.
219 With SelectSelectedWord can this be highlighted really
221 char* SelectNextWord(float &value);
223 void SelectSelectedWord();
225 void SetCursor(LyXParagraph *par, int pos);
227 void SetCursorIntern(LyXParagraph *par, int pos);
229 void SetCursorFromCoordinates(int x, long y);
239 void CursorLeftOneWord();
241 void CursorRightOneWord();
243 void CursorUpParagraph();
245 void CursorDownParagraph();
261 void DeleteWordForward();
263 void DeleteWordBackward();
265 void DeleteLineForward();
267 int SelectWordWhenUnderCursor();
268 /// Change the case of the word at cursor position
269 /** action is 0 for lower case, 1 for capitalization and 2 for
272 void ChangeWordCase(int action);
274 /** returns a printed row in a pixmap. The y value is needed to
275 decide, wether it is selected text or not. This is a strange
278 void GetVisibleRow(LyXScreen &scr, int offset,
279 Row *row_ptr, long y);
283 void ToggleFootnote();
287 void OpenFootnotes();
291 void CloseFootnotes();
293 void CloseFootnote();
295 /** turn the selection into a new environment. If there is no
296 selection, create an empty environment
298 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
300 void MeltFootnoteEnvironment();
302 void CutSelection(bool = true);
304 void CopySelection();
306 void PasteSelection();
308 void copyEnvironmentType();
310 void pasteEnvironmentType();
312 void InsertFootnote();
314 void InsertMarginpar();
318 void InsertTabular();
320 /** the DTP switches for paragraphs. LyX will store the top settings
321 always in the first physical paragraph, the bottom settings in the
322 last. When a paragraph is broken, the top settings rest, the bottom
323 settings are given to the new one. So I can make shure, they do not
324 duplicate themself (and you cannnot make dirty things with them! )
326 void SetParagraph(bool line_top, bool line_bottom,
327 bool pagebreak_top, bool pagebreak_bottom,
328 VSpace space_top, VSpace space_bottom,
330 string labelwidthstring,
332 void SetParagraphExtraOpt(int type,
335 int alignment, bool hfill,
336 bool start_minipage);
338 /* these things are for search and replace */
340 /** returns true if the specified string is at the specified
343 bool IsStringInText(LyXParagraph *par, int pos, char const* string);
345 /** sets the selection over the number of characters of string,
348 void SetSelectionOverString(char const* string);
350 /** simple replacing. The font of the first selected character
353 void ReplaceSelectionWithString(char const* string);
355 /** if the string can be found: return true and set the cursor to
357 bool SearchForward(char const* string);
358 bool SearchBackward(char const* string);
360 /// needed to insert the selection
361 void InsertStringA(char* string);
362 /// needed to insert the selection
363 void InsertStringB(char* string);
365 /// usefull when texing from within LyX
366 bool GotoNextError();
368 /// just another feature :)
371 /** needed to switch between different classes this works
372 for a list of paragraphs beginning with the specified par
373 return value is the number of wrong conversions
375 int SwitchLayoutsBetweenClasses(char class1, char class2, LyXParagraph *par);
377 /* for the greater insets */
379 /// returns 0 if inset wasn't found
380 int UpdateInset(Inset* inset);
382 void CheckParagraph(LyXParagraph* par, int pos);
384 /* table stuff -- begin*/
386 /** all table features of the text-class are put together in
387 this function. Possible values of feature are defined in table.h
389 void TableFeatures(int feature,string val);
391 void TableFeatures(int feature);
393 int NumberOfCell(LyXParagraph *par, int pos);
395 /** pos points at the beginning of the next cell (if there is one)
397 int WidthOfCell(LyXParagraph *par, int &pos);
399 void InsertCharInTable(char c);
401 void BackspaceInTable();
403 void CheckParagraphInTable(LyXParagraph* par, int pos);
405 char HitInTable(Row* row, int x);
407 bool MouseHitInTable(int x, long y);
408 /* table stuff -- end*/
410 LyXParagraph* GetParFromID(int id);
413 /// returns false if no undo possible
415 /// returns false if no redo possible
417 /// used by TextUndo/TextRedo
418 bool TextHandleUndo(Undo* undo);
419 /// makes sure the next operation will be stored
421 /// this is dangerous and for internal use only
423 /// this is dangerous and for internal use only
425 /// the flag used by FinishUndo();
430 void SetUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
432 void SetRedo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
434 Undo *CreateUndo(Undo::undo_kind kind, LyXParagraph *before, LyXParagraph *end);
435 /// for external use in lyx_cb.C
436 void SetCursorParUndo();
438 void CursorLeftIntern();
440 void CursorRightIntern();
442 void RemoveTableRow(LyXCursor *cursor);
444 bool IsEmptyTableRow(LyXCursor *cursor);
446 bool IsEmptyTableCell();
448 void toggleAppendix();
456 /** Copybuffer for copy environment type
457 Asger has learned that this should be a buffer-property instead
458 Lgb has learned that 'char' is a lousy type for non-characters
462 /// the currentrow is needed to access rows faster*/
463 Row* currentrow; /* pointer to the current row */
464 /// position in the text
466 /// width of the paper
467 unsigned short paperwidth;
469 /** inserts a new row behind the specified row, increments
470 * the touched counters */
471 void InsertRow(Row *row, LyXParagraph *par, int pos );
473 /** removes the row and reset the touched counters */
474 void RemoveRow(Row *row);
476 /** remove all following rows of the paragraph of the specified row. */
477 void RemoveParagraph(Row *row);
479 /** insert the specified paragraph behind the specified row */
480 void InsertParagraph(LyXParagraph *par, Row *row);
482 /** appends the implizit specified paragraph behind the specified row,
483 * start at the implizit given position */
484 void AppendParagraph(Row *row);
487 void BreakAgain(Row *row);
489 void BreakAgainOneRow(Row *row);
491 void SetHeightOfRow(Row *row_ptr); /* calculate and set the height
494 /** this calculates the specified parameters. needed when setting
495 * the cursor and when creating a visible row */
496 void PrepareToPrint(Row *row, float &x, float &fill_separator,
497 float &fill_hfill, float &fill_label_hfill);
499 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
501 /** Updates all counters starting BEHIND the row. Changed paragraphs
502 * with a dynamic left margin will be rebroken. */
503 void UpdateCounters(Row *row);
505 void SetCounter(LyXParagraph *par);
508 * some low level functions
512 int SingleWidth(LyXParagraph *par, int pos);
514 int SingleWidth(LyXParagraph *par, int pos, char c);
516 void Draw(Row *row, int &pos, LyXScreen &scr, int offset, float &x);
517 /// get the next breakpoint in a given paragraph
518 int NextBreakPoint(Row* row, int width);
519 /// returns the minimum space a row needs on the screen in pixel
520 int Fill(Row *row, int paperwidth);
522 /** returns the minimum space a manual label needs on the
524 int LabelFill(Row *row);
527 int BeginningOfMainBody(LyXParagraph *par);
529 /** Returns the left beginning of the text.
530 This information cannot be taken from the layouts-objekt, because
531 in LaTeX the beginning of the text fits in some cases
532 (for example sections) exactly the label-width.
534 int LeftMargin(Row *row);
536 int RightMargin(Row *row);
538 int LabelEnd (Row *row);
540 /** returns the number of separators in the specified row.
541 The separator on the very last column doesnt count
543 int NumberOfSeparators(Row *row);
545 /** returns the number of hfills in the specified row. The
546 LyX-Hfill is a LaTeX \hfill so that the hfills at the
547 beginning and at the end were ignored. This is {\em MUCH}
548 more usefull than not to ignore!
550 int NumberOfHfills(Row *row);
552 /// like NumberOfHfills, but only those in the manual label!
553 int NumberOfLabelHfills(Row *row);
555 /** returns true, if a expansion is needed. Rules are given by
558 bool HfillExpansion(Row *row_ptr, int pos);
560 /** returns the paragraph position of the last character in the
563 int RowLast(Row *row);