]> git.lyx.org Git - lyx.git/blobdiff - src/layout.h
Just some changes to be able to change TabularFeatures with the Table menu
[lyx.git] / src / layout.h
index a31aede905fb092baa6a082c6fc9303ce3c1dcc1..f29ebb2572af29ea635f69e9ea31c525f1da9386 100644 (file)
@@ -1,32 +1,47 @@
 // -*- C++ -*-
 /* This file is part of
  * ======================================================
-* 
-*           LyX, The Document Processor
-*       
-*          Copyright (C) 1995 Matthias Ettrich
-*
-*======================================================*/
+ * 
+ *           LyX, The Document Processor
+ *      
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2000 The LyX Team.
+ *
+ * ====================================================== */
 
-#ifndef _LAYOUT_H
-#define _LAYOUT_H
+#ifndef LAYOUT_H
+#define LAYOUT_H
+
+#include <vector>
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-#include "definitions.h"
 #include "lyxlex.h"
 #include "lyxfont.h"
 #include "Spacing.h"
 
+
 /// Reads the style files
-void LyXSetStyle();
+extern void LyXSetStyle();
+
+///
+enum { // no good name for this
+       ///
+        LYX_ENVIRONMENT_DEFAULT = 97,
+       ///
+       LYX_LAYOUT_DEFAULT = 99
+};
+// Could this cause confusion that both DUMMY_LAYOUT and  LAYOUT_DEFAULT has
+// the same value? (Lgb)
+///
+#define LYX_DUMMY_LAYOUT 99
 
 /// The different output types
 enum OutputType {
         ///
-        LATEX,
+        LATEX = 1,
        ///
        LINUXDOC,
        ///
@@ -38,7 +53,7 @@ enum OutputType {
 /// The different margin types
 enum LYX_MARGIN_TYPE {
        ///
-       MARGIN_MANUAL,
+       MARGIN_MANUAL = 1,
        ///
        MARGIN_FIRST_DYNAMIC,
        ///
@@ -49,8 +64,11 @@ enum LYX_MARGIN_TYPE {
        MARGIN_RIGHT_ADDRESS_BOX
 };
 
+
 ///
-enum LYX_ALIGNMENT {
+enum LyXAlignment {
+       ///
+       LYX_ALIGN_NONE = 0,
        ///
        LYX_ALIGN_BLOCK = 1,
        ///
@@ -65,10 +83,16 @@ enum LYX_ALIGNMENT {
         LYX_ALIGN_SPECIAL = 32
 };
 
+
+inline
+void operator|=(LyXAlignment & la1, LyXAlignment la2) {
+       la1 = static_cast<LyXAlignment>(la1 | la2);
+}
+
 /// The different LaTeX-Types
 enum LYX_LATEX_TYPES {
        ///
-       LATEX_PARAGRAPH,
+       LATEX_PARAGRAPH = 1,
        ///
        LATEX_COMMAND,
        ///
@@ -121,27 +145,42 @@ enum LYX_LABEL_TYPES {
        LABEL_FIRST_COUNTER = LABEL_COUNTER_CHAPTER
 };
 
-
+enum LYX_END_LABEL_TYPES {
+       ///
+       END_LABEL_NO_LABEL,
+       ///
+       END_LABEL_BOX,
+       ///
+       END_LABEL_FILLED_BOX,
+       ///
+       END_LABEL_ENUM_FIRST = END_LABEL_NO_LABEL,
+       ///
+       END_LABEL_ENUM_LAST = END_LABEL_FILLED_BOX
+};
+               
 /* Fix labels are printed flushright, manual labels flushleft. 
-* MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
-* MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL. 
-* This seems a funny restriction, but I think other combinations are
-* not needed, so I will not change it yet. 
-* Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC */
+ * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
+ * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL. 
+ * This seems a funny restriction, but I think other combinations are
+ * not needed, so I will not change it yet. 
+ * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC
+ */
 
 
 /* There is a parindent and a parskip. Which one is used depends on the 
-* paragraph_separation-flag of the text-object. 
-* BUT: parindent is only thrown away, if a parskip is defined! So if you
-* want a space between the paragraphs and a parindent at the same time, 
-* you should set parskip to zero and use topsep, parsep and bottomsep.
-* 
-* The standard layout is an exception: its parindent is only set, if the 
-* previous paragraph is standard too. Well, this is LateX and it is good! */ 
+ * paragraph_separation-flag of the text-object. 
+ * BUT: parindent is only thrown away, if a parskip is defined! So if you
+ * want a space between the paragraphs and a parindent at the same time, 
+ * you should set parskip to zero and use topsep, parsep and bottomsep.
+ * 
+ * The standard layout is an exception: its parindent is only set, if the 
+ * previous paragraph is standard too. Well, this is LateX and it is good!
+ */ 
 
 
 /// Attributes of a layout/paragraph environment
-class LyXLayoutList;
+class LyXTextClass;
+
 ///
 class LyXLayout {
 public:
@@ -149,76 +188,67 @@ public:
        LyXLayout ();
 
        ///
-       ~LyXLayout ();
-
-       ///
-       void Copy (LyXLayout const &l);
-
-       ///
-       bool Read (LyXLex&, LyXLayoutList *);
-
-       /// Name of the layout/paragraph environment
-       LString name;
-
-       /// Name of an layout that has replaced this layout. 
-       /** This is used to rename a layout, while keeping backward
-           compatibility 
-       */
-       LString obsoleted_by;
-
-       /// Default font for this layout/environment
-       /** The main font for this kind of environment. If an attribute has
-       LyXFont::INHERITED_*, it means that the value is specified by
-       the defaultfont for the entire layout. If we are nested, the font 
-       is inherited from the font in the environment one level up until the 
-       font is resolved. The values LyXFont::IGNORE_* and LyXFont::TOGGLE 
-       are illegal here.
+       bool Read (LyXLex &, LyXTextClass const &);
+       void readAlign(LyXLex &);
+       void readAlignPossible(LyXLex &);
+       void readLabelType(LyXLex &);
+       void readEndLabelType(LyXLex &);
+       void readMargin(LyXLex &);
+       void readLatexType(LyXLex &);
+       void readSpacing(LyXLex &);
+       string const & name() const { return name_; }
+       void name(string const & n) { name_ = n; }
+       string const & obsoleted_by() const { return obsoleted_by_; }
+       string const & latexname() const { return latexname_; }
+       string const & labelstring() const { return labelstring_; }
+       string const & preamble() const { return preamble_; }
+       string const & latexparam() const { return latexparam_; }
+       string const & labelstring_appendix() const {
+               return labelstring_appendix_;
+       }
+       /** Default font for this layout/environment.
+           The main font for this kind of environment. If an attribute has
+           LyXFont::INHERITED_*, it means that the value is specified by
+           the defaultfont for the entire layout. If we are nested, the
+           font is inherited from the font in the environment one level
+           up until the font is resolved. The values LyXFont::IGNORE_*
+           and LyXFont::TOGGLE are illegal here.
        */
        LyXFont font;
 
-       /// Default font for labels
-       /** Interpretation the same as for font above */
+       /** Default font for labels.
+           Interpretation the same as for font above
+       */
        LyXFont labelfont;
 
-       /// Resolved version of the font for this layout/environment
-       /** This is a resolved version the default font. The font is resolved
-       against the defaultfont of the entire layout. */
+       /** Resolved version of the font for this layout/environment.
+           This is a resolved version the default font. The font is resolved
+           against the defaultfont of the entire layout.
+       */
        LyXFont resfont;
 
-       /// Resolved version of the font used for labels
-       /** This is a resolved version the label font. The font is resolved
-       against the defaultfont of the entire layout. */
+       /** Resolved version of the font used for labels.
+           This is a resolved version the label font. The font is resolved
+           against the defaultfont of the entire layout.
+       */
        LyXFont reslabelfont;
 
        /// Text that dictates how wide the left margin is on the screen
-       LString leftmargin;
+       string leftmargin;
 
        /// Text that dictates how wide the right margin is on the screen
-       LString rightmargin;
+       string rightmargin;
 
        /// Text that dictates how much space to leave after a potential label
-       LString labelsep;
+       string labelsep;
 
        /// Text that dictates how much space to leave before a potential label
-       LString labelindent;
+       string labelindent;
 
-       /// Text that dictates the width of the indentation of indented paragraphs
-       LString parindent;
-
-       /// Label string. "Abstract", "Reference", "Caption"...
-       LString labelstring;
-
-       /// Label string inside appendix. "Appendix", ...
-       LString labelstring_appendix;
-
-       /// LaTeX name for environment
-       LString latexname;
-
-       /// LaTeX parameter for environment
-        LString latexparam;   //arrae970411
-
-        /// Macro definitions needed for this layout
-       LString preamble;
+       /** Text that dictates the width of the indentation of
+           indented paragraphs.
+       */
+       string parindent;
 
        ///
        float parskip;
@@ -242,16 +272,19 @@ public:
        Spacing spacing;
 
        ///
-       char align; // add approp. signedness
+       LyXAlignment align;
 
        ///
-       char alignpossible; // add approp. signedness
+       LyXAlignment alignpossible;
 
        ///
-       char labeltype; // add approp. signedness
+       char labeltype; // add approp. type
 
        ///
-       char margintype; // add approp. signedness
+       char endlabeltype;
+
+       ///
+       LYX_MARGIN_TYPE margintype;
 
        ///
        bool fill_top;
@@ -278,7 +311,7 @@ public:
        }
        ///
        bool isCommand() const { 
-           return latextype == LATEX_COMMAND;
+               return latextype == LATEX_COMMAND;
        }
        ///
        bool isEnvironment() const {
@@ -290,192 +323,259 @@ public:
        LYX_LATEX_TYPES latextype;
        /// Does this object belong in the title part of the document?
        bool intitle;
+private:
+       /// Name of the layout/paragraph environment
+       string name_;
+
+       /** Name of an layout that has replaced this layout.
+           This is used to rename a layout, while keeping backward
+           compatibility 
+       */
+       string obsoleted_by_;
+
+       /// LaTeX name for environment
+       string latexname_;
+
+       /// Label string. "Abstract", "Reference", "Caption"...
+       string labelstring_;
+
+       /// Label string inside appendix. "Appendix", ...
+       string labelstring_appendix_;
+
+       /// LaTeX parameter for environment
+        string latexparam_;
+
+        /// Macro definitions needed for this layout
+       string preamble_;
 };
 
 
 ///
-class LyXLayoutList {
+class LyXTextClass {
 public:
        ///
-       LyXLayoutList();
+       typedef std::vector<LyXLayout> LayoutList;
        ///
-       ~LyXLayoutList();
+       typedef LayoutList::const_iterator const_iterator;
        ///
-       void Add (LyXLayout *l);
+       typedef LayoutList::size_type size_type;
        ///
-       bool Delete (LString const &name);
-        ///
-       LyXLayout *GetLayout (LString const &name);
-       ///
-       LyXLayout *ToAr();
+       explicit
+       LyXTextClass (string const & = string(), 
+                     string const & = string(), 
+                     string const & = string());
+
        ///
-       int GetNum();
+       const_iterator begin() const { return layoutlist.begin(); }
        ///
-       void Clean(); 
-private:
+       const_iterator end() const { return layoutlist.end(); }
+       
        ///
-       struct LyXLayoutL {
-               ///
-               LyXLayout* layout;
-               ///
-               LyXLayoutL *next;
-       };
+       bool Read(string const & filename, bool merge = false);
+       void readOutputType(LyXLex &);
+       void readMaxCounter(LyXLex &);
+       void readClassOptions(LyXLex &);
        ///
-       LyXLayoutL * l;
+       bool hasLayout(string const & name) const;
+
        ///
-       LyXLayoutL *eol;
+       LyXLayout const & GetLayout(string const & vname) const;
+
        ///
-       int num_layouts;
-};
+       LyXLayout & GetLayout(string const & vname);
 
+       /// Sees to that the textclass structure has been loaded
+       void load();
 
-///
-class LyXTextClass  {
-public:
        ///
-       LyXTextClass (LString const & = LString(), 
-                     LString const & = LString(), 
-                     LString const & = LString());
+       string const & name() const { return name_; }
+       ///
+       string const & latexname() const { return latexname_; }
+       ///
+       string const & description() const { return description_; }
+       ///
+       string const & opt_fontsize() const { return opt_fontsize_; }
+       ///
+       string const & opt_pagestyle() const { return opt_pagestyle_; }
+       ///
+       string const & options() const { return options_; }
+       ///
+       string const & pagestyle() const { return pagestyle_; }
+       ///
+       string const & preamble() const { return preamble_; }
+
+       /// Packages that are already loaded by the class
+       enum Provides {
+               nothing = 0,
+               amsmath = 1,
+               makeidx = 2,
+               url = 4
+       };
+       bool provides(Provides p) const { return provides_ & p; }
+       
+       ///
+       unsigned int columns() const { return columns_; }
+       ///
+       enum PageSides {
+               OneSide,
+               TwoSides
+       };
+       ///
+       PageSides sides() const { return sides_; }
+       ///
+       int secnumdepth() const { return secnumdepth_; }
        ///
-       ~LyXTextClass();
+       int tocdepth() const { return tocdepth_; }
 
-       /// Not a real copy, just reference!
-       void Copy (LyXTextClass const &l);
+        ///
+        OutputType outputType() const { return outputType_; }
 
-       /// Reads a textclass structure from file
-       int Read (LString const & filename, LyXLayoutList *list = NULL);
+       ///
+       LyXFont const & defaultfont() const { return defaultfont_; }
 
-       /// Sees to that the textclass structure has been loaded
-       void load();
+       /// Text that dictates how wide the left margin is on the screen
+       string const & leftmargin() const { return leftmargin_; }
 
+       /// Text that dictates how wide the right margin is on the screen
+       string const & rightmargin() const { return rightmargin_; }
+        ///
+       int maxcounter() const { return maxcounter_; }
        ///
-       LString name;
+       size_type numLayouts() const { return layoutlist.size(); }
        ///
-       LString latexname;
+       LyXLayout const & operator[](size_type i) const {
+               return layoutlist[i];
+       }
+private:
        ///
-       LString description;
-        ///
-        OutputType output_type;
-
-       /// Specific class options
-        LString opt_fontsize;
+       bool delete_layout(string const &);
        ///
-        LString opt_pagestyle;
+       bool do_readStyle(LyXLex &, LyXLayout &);
        ///
-       LString options;
-
-       /// Packages that are already loaded by the class
-       bool provides_amsmath;
+       string name_;
        ///
-       bool provides_makeidx;
-       /// 
-       bool provides_url;
-    
-       /// Base font. This one has to be fully instantiated.
-       /** Base font. The paragraph and layout fonts are resolved against
-       this font. Attributes LyXFont::INHERIT, LyXFont::IGNORE, and 
-       LyXFont::TOGGLE are extremely illegal.
-       */
-       LyXFont defaultfont;
-       /// Array of styles in this textclass
-       LyXLayout* style;
+       string latexname_;
        ///
-       unsigned char number_of_defined_layouts;
+       string description_;
+       /// Specific class options
+        string opt_fontsize_;
        ///
-       unsigned char columns;
+        string opt_pagestyle_;
        ///
-       unsigned char sides;
+       string options_;
        ///
-       signed char secnumdepth;
+       string pagestyle_;
        ///
-       signed char tocdepth;
+       string preamble_;
        ///
-       LString pagestyle;
+       Provides provides_;
        ///
-       LString preamble;
+       unsigned int columns_;
        ///
-       /// Text that dictates how wide the left margin is on the screen
-       LString leftmargin;
+       PageSides sides_;
+       ///
+       int secnumdepth_;
+       ///
+       int tocdepth_;
         ///
+        OutputType outputType_;
+       /** Base font. The paragraph and layout fonts are resolved against
+           this font. This has to be fully instantiated. Attributes
+           LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
+           extremely illegal.
+       */
+       LyXFont defaultfont_;
+       /// Text that dictates how wide the left margin is on the screen
+       string leftmargin_;
+
        /// Text that dictates how wide the right margin is on the screen
-       LString rightmargin;
+       string rightmargin_;
         ///
-       char maxcounter; // add approp. signedness
-private:
+       int maxcounter_; // add approp. signedness
+
+       ///
+       LayoutList layoutlist;
+
        /// Has this layout file been loaded yet?
        bool loaded;
 };
 
 
+///
+inline
+void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
+{
+       p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
+}
+
+
+///
+std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);
+
+
 ///
 class LyXTextClassList {
 public:
        ///
-       LyXTextClassList();
-
+       typedef std::vector<LyXTextClass> ClassList;
        ///
-       ~LyXTextClassList();
-
+       typedef ClassList::const_iterator const_iterator;
+       ///
+       typedef ClassList::size_type size_type;
+       ///
+       const_iterator begin() const { return classlist.begin(); }
+       ///
+       const_iterator end() const { return classlist.end(); }
+       
        /// Gets layout structure from layout number and textclass number
-       LyXLayout *Style(char textclass, char layout);
+       LyXLayout const & Style(size_type textclass,
+                               LyXTextClass::size_type layout) const;
 
        /// Gets layout number from textclass number and layout name
-       char NumberOfLayout(char textclass, LString const & name); // add approp. signedness
+       std::pair<bool, LyXTextClass::size_type>
+       NumberOfLayout(size_type textclass,
+                      string const & name) const;
 
        /// Gets a layout name from layout number and textclass number
-       LString NameOfLayout(char textclass, char layout); // add approp. signedness
+       string const &
+       NameOfLayout(size_type textclass,
+                    LyXTextClass::size_type layout) const;
 
-       /// Gets textclass number from name
-       /** Returns -1 if textclass name does not exist */
-       signed char NumberOfClass(LString const & textclass);
+       /** Gets textclass number from name.
+           Returns -1 if textclass name does not exist
+       */
+       std::pair<bool, size_type>
+       NumberOfClass(string const & textclass) const;
 
        ///
-       LString NameOfClass(char number); // add approp. signedness
+       string const & NameOfClass(size_type number) const;
 
        ///
-       LString LatexnameOfClass(char number); // add approp. signedness
+       string const & LatexnameOfClass(size_type number) const;
 
        ///
-       LString DescOfClass(char number); // add approp. signedness
+       string const & DescOfClass(size_type number) const;
 
        ///
-       LyXTextClass * TextClass(char textclass); // add approp. signedness
+       LyXTextClass const & TextClass(size_type textclass) const;
 
-       /// Read textclass list
-       /** Returns false if this fails */
+       /** Read textclass list.
+           Returns false if this fails
+       */
        bool Read();
 
-       /// Load textclass
-       /** Returns false if this fails */
-       bool Load(const char number);
+       /** Load textclass.
+           Returns false if this fails
+       */
+       bool Load(size_type number) const;
 private:
        ///
-       struct LyXTextClassL {
-               ///
-               LyXTextClass * textclass;
-               ///
-               LyXTextClassL * next;
-       };
-
-       ///
-       LyXTextClassL * l;
-
+       mutable ClassList classlist;
        ///
-       int num_textclass;
-
-       /// After reading, this arrays holds the textclasses
-       LyXTextClass * ar;
-
-       /// Add a textclass to list
-       void Add (LyXTextClass *l);
-
-       /// Convert final linked list to array
-       /** We read the textclasses into a linked list. After the reading,
-       the list is converted to an array, and the linked list is nuked. */
-       void ToAr();
+       void Add (LyXTextClass const &);
 };
 
 /// Should not be declared here!! (Lgb) Why not? (Asger)
-extern LyXTextClassList lyxstyle;
+extern LyXTextClassList textclasslist;
  
 #endif