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 * ====================================================== */
12 #ifndef LYXPARAGRAPH_H
13 #define LYXPARAGRAPH_H
29 //#define __STD_STUFF 1
33 #include "definitions.h"
34 #include "insets/lyxinset.h"
36 #include "support/textutils.h"
38 #include "insets/insetbib.h"
46 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
70 ALGORITHM, // Bernhard, 970807
72 WIDE_FIG, // CFO-G, 971106
74 WIDE_TAB // CFO-G, 971106
79 /// this konstruktor inserts the new paragraph in a list
80 LyXParagraph(LyXParagraph * par);
81 /// the destruktors removes the new paragraph from the list
85 void writeFile(FILE *, BufferParams &, char, char);
88 void validate(LaTeXFeatures &);
95 void SetID(int id_arg){
100 /** allocates more memory for the specified paragraph
101 pos is needed to specify the paragraph correctly. Remember the
104 void Enlarge(int pos, int number);
105 /** make the allocated memory fit to the needed size
106 used to make a paragraph smaller
115 void readSimpleWholeFile(FILE *);
118 LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
119 string & foot, TexRow & foot_texrow,
123 LyXParagraph * TeXEnvironment(string & file, TexRow & texrow,
124 string & foot, TexRow & foot_texrow,
128 LyXParagraph * Clone();
131 bool HasSameLayout(LyXParagraph * par);
134 void MakeSameLayout(LyXParagraph * par);
136 /// Is it the first par with same depth and layout?
137 bool IsFirstInSequence() {
138 LyXParagraph * dhook = DepthHook(GetDepth());
139 return (dhook == this
140 || dhook->GetLayout() != GetLayout()
141 || dhook->GetDepth() != GetDepth());
147 typedef char value_type;
149 typedef vector<value_type> TextContainer;
150 //typedef deque<char> TextContainer;
151 //typedef rope<char> TextContainer;
152 typedef int size_type;
156 size_type size() const { return text.size(); }
166 VSpace added_space_top;
169 VSpace added_space_bottom;
172 LyXTextClass::LayoutList::size_type layout;
176 \item no footnote, closed footnote,
177 \item open footnote, where footnote
178 \item means footnote-environment
181 footnote_flag footnoteflag;
183 /// footnote, margin, fig, tab
184 footnote_kind footnotekind;
186 //@Man: the LyX- DTP-switches
198 bool pagebreak_bottom;
214 void setCounter(int i, int v) { counter[i] = v; }
215 int getCounter(int i) { return counter[i]; }
216 void incCounter(int i) { counter[i]++; }
218 bool start_of_appendix;
229 /* This is for the paragraph extra stuff */
235 string pextra_widthp;
237 int pextra_alignment;
241 bool pextra_start_minipage;
247 string labelwidthstring;
253 LyXParagraph * previous;
255 /* table stuff -- begin*/
258 /* table stuff -- end*/
261 InsetBibKey * bibkey; // ale970302
263 /** these function are able to hide closed footnotes
265 LyXParagraph * Next();
268 LyXParagraph * Previous();
270 /** these function are able to hide open and closed footnotes
272 LyXParagraph * NextAfterFootnote();
274 LyXParagraph * PreviousBeforeFootnote();
276 LyXParagraph * LastPhysicalPar();
278 LyXParagraph * FirstPhysicalPar();
281 /// returns the physical paragraph
282 LyXParagraph * ParFromPos(size_type pos);
283 /// returns the position in the physical par
284 int PositionInParFromPos(size_type pos);
286 /// returns the physical paragraph
287 LyXParagraph * ParFromPos(int pos);
288 /// returns the position in the physical par
289 int PositionInParFromPos(int pos);
292 /// for the environments
293 LyXParagraph * DepthHook(int depth);
295 int BeginningOfMainBody();
297 string GetLabestring();
299 /// the next two functions are for the manual labels
300 string GetLabelWidthString();
302 void SetLabelWidthString(string const & s);
304 LyXTextClass::LayoutList::size_type GetLayout();
310 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
312 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
314 int GetFirstCounter(int i);
319 void Erase(size_type pos);
320 /** the flag determines wether the layout should be copied
322 void BreakParagraph(size_type pos, int flag);
324 void BreakParagraphConservative(size_type pos);
325 /** Get unistantiated font setting. Returns the difference
326 between the characters font and the layoutfont.
327 This is what is stored in the fonttable
329 LyXFont GetFontSettings(size_type pos);
330 /** Get fully instantiated font. If pos == -1, use the layout
331 font attached to this paragraph.
332 If pos == -2, use the label font of the layout attached here.
333 In all cases, the font is instantiated, i.e. does not have any
334 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
337 LyXFont getFont(size_type pos);
339 char GetChar(size_type pos);
341 void SetFont(size_type pos, LyXFont const & font);
343 string GetWord(size_type &);
344 /// Returns the height of the highest font in range
345 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos, size_type endpos) const;
347 void InsertChar(size_type pos, char c);
349 void InsertInset(size_type pos, Inset * inset);
351 Inset * GetInset(size_type pos);
353 Inset * ReturnNextInsetPointer(size_type & pos);
355 void OpenFootnote(size_type pos);
357 void CloseFootnote(size_type pos);
358 /// important for cut and paste
359 void CopyIntoMinibuffer(size_type pos);
361 void CutIntoMinibuffer(size_type pos);
363 void InsertFromMinibuffer(size_type pos);
365 bool IsHfill(size_type pos) {
366 return IsHfillChar(GetChar(pos));
370 bool IsInset(size_type pos) {
371 return IsInsetChar(GetChar(pos));
375 bool IsFloat(size_type pos) {
376 return IsFloatChar(GetChar(pos));
380 bool IsNewline(size_type pos) {
383 tmp= IsNewlineChar(GetChar(pos));
388 bool IsSeparator(size_type pos) {
389 return IsSeparatorChar(GetChar(pos));
393 bool IsLineSeparator(size_type pos) {
394 return IsLineSeparatorChar(GetChar(pos));
398 bool IsKomma(size_type pos){
399 return IsKommaChar(GetChar(pos));
402 /// Used by the spellchecker
403 bool IsLetter(size_type pos);
406 bool IsWord(size_type pos ) {
407 return IsWordChar( GetChar(pos) ) ;
414 /** the flag determines wether the layout should be copied
416 void BreakParagraph(int pos, int flag);
418 void BreakParagraphConservative(int pos);
419 /** Get unistantiated font setting. Returns the difference
420 between the characters font and the layoutfont.
421 This is what is stored in the fonttable
423 LyXFont GetFontSettings(int pos);
424 /** Get fully instantiated font. If pos == -1, use the layout
425 font attached to this paragraph.
426 If pos == -2, use the label font of the layout attached here.
427 In all cases, the font is instantiated, i.e. does not have any
428 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
431 LyXFont getFont(int pos);
433 char GetChar(int pos);
435 void SetFont(int pos, LyXFont const & font);
437 string GetWord(int &);
438 /// Returns the height of the highest font in range
439 LyXFont::FONT_SIZE HighestFontInRange(int startpos, int endpos) const;
441 void InsertChar(int pos, char c);
443 void InsertInset(int pos, Inset * inset);
445 Inset * GetInset(int pos);
447 Inset * ReturnNextInsetPointer(int & pos);
449 void OpenFootnote(int pos);
451 void CloseFootnote(int pos);
452 /// important for cut and paste
453 void CopyIntoMinibuffer(int pos);
455 void CutIntoMinibuffer(int pos);
457 void InsertFromMinibuffer(int pos);
459 bool IsHfill(int pos) {
460 return IsHfillChar(GetChar(pos));
464 bool IsInset(int pos) {
465 return IsInsetChar(GetChar(pos));
469 bool IsFloat(int pos) {
470 return IsFloatChar(GetChar(pos));
474 bool IsNewline(int pos) {
477 tmp= IsNewlineChar(GetChar(pos));
482 bool IsSeparator(int pos) {
483 return IsSeparatorChar(GetChar(pos));
487 bool IsLineSeparator(int pos) {
488 return IsLineSeparatorChar(GetChar(pos));
492 bool IsKomma(int pos){
493 return IsKommaChar(GetChar(pos));
496 /// Used by the spellchecker
497 bool IsLetter(int pos);
500 bool IsWord( int pos ) {
501 return IsWordChar( GetChar(pos) ) ;
504 /** This one resets all layout and dtp switches but not the font
505 of the single characters
509 /** paste this paragraph with the next one
510 be carefull, this doesent make any check at all
512 void PasteParagraph();
514 /// used to remove the error messages
515 int AutoDeleteInsets();
517 /// returns -1 if inset not found
518 int GetPositionOfInset(Inset * inset);
520 /// ok and now some footnote functions
521 void OpenFootnotes();
524 void CloseFootnotes();
527 LyXParagraph * FirstSelfrowPar();
530 int ClearParagraph(){
532 if (!IsDummy() && !table){
535 || IsLineSeparator(0))){
543 /** A paragraph following a footnote is a "dummy". A paragraph
544 with a footnote in it is stored as three paragraphs:
545 First a paragraph with the text up to the footnote, then
546 one (or more) paragraphs with the footnote, and finally
547 the a paragraph with the text after the footnote. Only the
548 first paragraph keeps information about layoutparameters, */
550 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
551 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
554 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
555 I have to set it on each of it's elements */
557 void SetPExtraType(int type, char const * width, char const * widthp);
559 void UnsetPExtraType();
562 bool RoffContTableRows(FILE * file, size_type i,
565 void DocBookContTableRows(string & file, string & extra, int & desc_on,
567 int current_cell_number, int & column);
570 bool RoffContTableRows(FILE * file, int i, int actcell);
572 void DocBookContTableRows(string & file, string & extra, int & desc_on,
573 int i, int current_cell_number, int & column);
576 bool linuxDocConvertChar(char c, string & sgml_string);
578 void SimpleDocBookOneTablePar(string & file, string & extra,
579 int & desc_on, int depth);
581 /** A font entry covers a range of positions. Notice that the
582 entries in the list are inserted in random order.
583 I don't think it's worth the effort to implement a more effective
584 datastructure, because the number of different fonts in a paragraph
589 /// Start position of paragraph this font attribute covers
591 /// Ending position of paragraph this font attribute covers
594 /// Start position of paragraph this font attribute covers
596 /// Ending position of paragraph this font attribute covers
599 /** Font. Interpretation of the font values:
600 If a value is LyXFont::INHERIT_*, it means that the font
601 attribute is inherited from either the layout of this
602 paragraph or, in the case of nested paragraphs, from the
603 layout in the environment one level up until completely
605 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
606 allowed in these font tables.
610 /// Pointer to next font entry
632 typedef list<FontTable> FontList;
634 typedef list<InsetTable> InsetList;
641 FontTable * fonttable;
643 InsetTable * insettable;
646 LyXParagraph * TeXDeeper(string & file, TexRow & texrow,
647 string & foot, TexRow & foot_texrow,
650 LyXParagraph * TeXFootnote(string & file, TexRow & texrow,
651 string & foot, TexRow & foot_texrow,
654 bool SimpleTeXOnePar(string & file, TexRow & texrow);
656 bool SimpleTeXOneTablePar(string & file, TexRow & texrow);
659 bool TeXContTableRows(string & file, size_type i,
660 int current_cell_number,
661 int & column, TexRow & texrow);
663 void SimpleTeXBlanks(string & file, TexRow & texrow,
665 int & column, LyXFont const & font,
666 LyXLayout const & style);
668 void SimpleTeXSpecialChars(string & file, TexRow & texrow,
669 LyXFont & font, LyXFont & running_font,
670 LyXFont & basefont, bool & open_font,
671 LyXLayout const & style,
673 int & column, char const c);
676 bool TeXContTableRows(string & file, int i, int current_cell_number,
677 int & column, TexRow & texrow);
679 void SimpleTeXBlanks(string & file, TexRow & texrow,
680 int const i, int & column, LyXFont const & font,
681 LyXLayout const & style);
683 void SimpleTeXSpecialChars(string & file, TexRow & texrow,
684 LyXFont & font, LyXFont & running_font,
685 LyXFont & basefont, bool & open_font,
686 LyXLayout const & style,
687 int & i, int & column, char const c);
692 static unsigned int paragraph_id;