This commit was manufactured by cvs2svn to create tag 'lyx-1_1_2'.
[lyx.git] / src / lyxtext.h
blob912f59e53dc1f5425d04e094d718e79605a7de41
1 // -*- C++ -*-
2 /* This file is part of
3 * ======================================================
4 *
5 * LyX, The Document Processor
6 *
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ======================================================*/
12 #ifndef LYXTEXT_H
13 #define LYXTEXT_H
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
19 #include "definitions.h"
20 #include "layout.h"
21 #include "lyxfont.h"
22 #include "lyxrow.h"
23 #include "undo.h"
24 #include "lyxcursor.h"
26 class Buffer;
27 class BufferParams;
28 class LyXScreen;
30 /**
31 This class holds the mapping between buffer paragraphs and screen rows.
33 class LyXText {
34 public:
35 ///
36 enum text_status {
37 ///
38 UNCHANGED,
39 ///
40 NEED_LITTLE_REFRESH,
41 ///
42 NEED_MORE_REFRESH,
43 ///
44 NEED_VERY_LITTLE_REFRESH
47 /// points to Buffer.params
48 BufferParams *parameters;
49 /// points to Buffer
50 Buffer *params;
51 ///
52 int number_of_rows;
53 ///
54 long height;
55 /// the current font settings
56 LyXFont current_font;
57 /// the current font
58 LyXFont real_current_font;
60 /// Constructor
61 LyXText(int paperwidth, Buffer *);
63 /// Destructor
64 ~LyXText();
66 ///
67 LyXFont GetFont(LyXParagraph* par, int pos);
68 ///
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
78 those paragraphs
80 void SetLayout(char layout);
82 /// used in setlayout
83 void MakeFontEntriesLayoutSpecific(LyXParagraph *par);
85 /** increment depth over selection and make a total rebreak of those
86 paragraphs
88 void IncDepth();
90 /** decrement depth over selection and make a total rebreak of those
91 paragraphs */
92 void DecDepth();
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
99 paragraphs.
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
106 parameters.
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
118 has changed.
120 void RedoHeightOfParagraph(LyXCursor cursor);
122 /** forces the redrawing of a paragraph. Needed when manipulating a
123 right address box
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
135 int FullRebreak();
137 /// may be important for the menu
138 char* GetLayout(int row);
140 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
142 Row* need_break_row;
144 long refresh_y;
146 int refresh_height;
148 int refresh_width;
150 int refresh_x;
152 Row *refresh_row;
154 int refresh_pos;
156 /** wether the screen needs a refresh,
157 starting with refresh_y
159 text_status status;
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
163 of this row
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
173 of the row
175 Row* GetRow(LyXParagraph *par, int pos, long &y);
177 /** returns the height of a default row, needed for scrollbar
179 int DefaultHeight();
181 /** The cursor.
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.
187 LyXCursor cursor;
189 /* the selection cursor */
190 ///
191 bool selection;
193 bool mark_set;
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:
209 void SetSelection();
211 void ClearSelection();
213 /// just selects the word the cursor is in
214 void SelectWord();
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);
231 void CursorUp();
233 void CursorDown();
235 void CursorLeft();
237 void CursorRight();
239 void CursorLeftOneWord();
241 void CursorRightOneWord();
243 void CursorUpParagraph();
245 void CursorDownParagraph();
247 void CursorHome();
249 void CursorEnd();
251 void CursorTab();
253 void CursorTop();
255 void CursorBottom();
257 void Delete();
259 void Backspace();
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
270 uppercase.
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
276 solution but faster.
278 void GetVisibleRow(LyXScreen &scr, int offset,
279 Row *row_ptr, long y);
281 /* footnotes: */
283 void ToggleFootnote();
285 void OpenStuff();
287 void OpenFootnotes();
289 void OpenFootnote();
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();
316 void InsertFigure();
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,
329 char align,
330 string labelwidthstring,
331 bool noindent);
332 void SetParagraphExtraOpt(int type,
333 const char *width,
334 const char *widthp,
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
341 position
343 bool IsStringInText(LyXParagraph *par, int pos, char const* string);
345 /** sets the selection over the number of characters of string,
346 no check!!
348 void SetSelectionOverString(char const* string);
350 /** simple replacing. The font of the first selected character
351 is used
353 void ReplaceSelectionWithString(char const* string);
355 /** if the string can be found: return true and set the cursor to
356 the new position */
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 :)
369 bool GotoNextNote();
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);
412 // undo functions
413 /// returns false if no undo possible
414 bool TextUndo();
415 /// returns false if no redo possible
416 bool TextRedo();
417 /// used by TextUndo/TextRedo
418 bool TextHandleUndo(Undo* undo);
419 /// makes sure the next operation will be stored
420 void FinishUndo();
421 /// this is dangerous and for internal use only
422 void FreezeUndo();
423 /// this is dangerous and for internal use only
424 void UnFreezeUndo();
425 /// the flag used by FinishUndo();
426 bool undo_finished;
427 /// a flag
428 bool undo_frozen;
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();
450 private:
452 Row* firstrow;
454 Row* lastrow;
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
460 char copylayouttype;
462 /// the currentrow is needed to access rows faster*/
463 Row* currentrow; /* pointer to the current row */
464 /// position in the text
465 long currentrow_y;
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
492 * of the row */
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
523 screen in pixel */
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
556 LaTeX
558 bool HfillExpansion(Row *row_ptr, int pos);
560 /** returns the paragraph position of the last character in the
561 specified row
563 int RowLast(Row *row);
566 #endif