]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.h
Fix compilation with Qt4.2
[lyx.git] / src / Counters.h
index 3a04d0313b9d159dc9cb2a38f2335d1550da016c..d992bbb3c646f64b003eca3928d7d2372642d388 100644 (file)
 #ifndef COUNTERS_H
 #define COUNTERS_H
 
+#include "OutputEnums.h"
+
 #include "support/docstring.h"
 
 #include <map>
+#include <deque>
 #include <vector>
 
 
 namespace lyx {
 
+class Layout;
 class Lexer;
 
 /// This represents a single counter.
@@ -53,6 +57,10 @@ public:
         *  want the version shown in an appendix.
         */
        docstring const & labelString(bool in_appendix) const;
+       /// Similar, but used for formatted references in XHTML output.
+       /// E.g., for a section counter it might be "section \thesection"
+       docstring const & prettyFormat() const { return prettyformat_; }
+       
        /// Returns a map of LaTeX-like strings to format the counter. 
        /** For each language, the string is similar to what one gets
         *  in LaTeX when using "\the<counter>". The \c in_appendix
@@ -75,6 +83,8 @@ private:
        docstring labelstring_;
        /// The same as labelstring_, but in appendices.
        docstring labelstringappendix_;
+       /// Similar, but used for formatted references in XHTML output
+       docstring prettyformat_;
        /// Cache of the labelstring with \\the<counter> expressions expanded, 
        /// indexed by language
        mutable StringMap flatlabelstring_;
@@ -111,10 +121,10 @@ public:
        int value(docstring const & ctr) const;
        /// Increment by one counter named by arg, and zeroes slave
        /// counter(s) for which it is the master.
-       /** Sub-slaves not zeroed! That happens at slave's first step
-        *  0->1. Seems to be sufficient.
-        */
-       void step(docstring const & ctr);
+       /// Sub-slaves are not zeroed! That happens at slave's first 
+       /// step 0->1. Seems to be sufficient.
+       /// \param utype determines whether we track the counters.
+       void step(docstring const & ctr, UpdateType utype);
        /// Reset all counters.
        void reset();
        /// Reset counters matched by match string.
@@ -134,6 +144,10 @@ public:
         */
        docstring counterLabel(docstring const & format,
                               std::string const & lang) const;
+       /// returns a formatted version of the counter, using the 
+       /// format given by Counter::prettyFormat().
+       docstring prettyCounter(docstring const & cntr,
+                              std::string const & lang) const;
        /// Are we in appendix?
        bool appendix() const { return appendix_; }
        /// Set the state variable indicating whether we are in appendix.
@@ -146,8 +160,30 @@ public:
        bool isSubfloat() const { return subfloat_; }
        /// Set the state variable indicating whether we are in a subfloat.
        void isSubfloat(bool s) { subfloat_ = s; }
+       
+       /// \name refstepcounter        
+       // @{
+       /// The currently active counter, so far as references go.
+       /// We're trying to track \refstepcounter in LaTeX, more or less.
+       /// Note that this may be empty.
+       docstring currentCounter() const;
+       /// Called during update labels as we go through various paragraphs,
+       /// to track the layouts as we go through.
+       void setActiveLayout(Layout const & lay);
+       /// Also for updateLabels().
+       /// Call this when entering things like footnotes, where there is now
+       /// no "last layout" and we want to restore the "last layout" on exit.
+       void clearLastLayout() { layout_stack_.push_back(0); }
+       /// Call then when existing things like footnotes.
+       void restoreLastLayout() { layout_stack_.pop_back(); }
+       /// 
+       void saveLastCounter()
+               { counter_stack_.push_back(counter_stack_.back()); }
+       /// 
+       void restoreLastCounter() { counter_stack_.pop_back(); }
+       // @}
 private:
-       /** expands recusrsively any \\the<counter> macro in the
+       /** expands recursively any \\the<counter> macro in the
         *  labelstring of \c counter.  The \c lang code is used to
         *  translate the string.
         */
@@ -162,6 +198,11 @@ private:
         */
        docstring labelItem(docstring const & ctr,
                            docstring const & numbertype) const;
+       /// Used for managing the counter_stack_.
+       // @{
+       void beginEnvironment();
+       void endEnvironment();
+       // @}
        /// Maps counter (layout) names to actual counters.
        typedef std::map<docstring, Counter> CounterList;
        /// Instantiate.
@@ -172,9 +213,12 @@ private:
        std::string current_float_;
        /// Are we in a subfloat?
        bool subfloat_;
+       /// Used to keep track of active counters.
+       std::deque<docstring> counter_stack_;
+       /// Same, but for last layout.
+       std::deque<Layout const *> layout_stack_;
 };
 
-
 } // namespace lyx
 
 #endif