]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.h
pimpl not needed here
[lyx.git] / src / insets / Inset.h
index a6b5090ef458b42e6c29a0c72c36a15a864ebef5..c38e44e67ddb88d39a532d8b3324cdde18652bc1 100644 (file)
@@ -5,8 +5,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alejandro Aguilar Sierra
- * \author Jürgen Vigna
- * \author Lars Gullik Bjønnes
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
  * \author Matthias Ettrich
  *
  * Full author contact details are available in file CREDITS.
 #ifndef INSETBASE_H
 #define INSETBASE_H
 
-#include "Changes.h"
-#include "Dimension.h"
+#include "ColorCode.h"
+#include "InsetCode.h"
 
-#include "support/docstream.h"
+#include "support/strfwd.h"
 
-#include <boost/signal.hpp>
-
-#include <memory>
 #include <vector>
 
 namespace lyx {
 
+class BiblioInfo;
 class Buffer;
 class BufferParams;
 class BufferView;
+class Change;
+class Cursor;
 class CursorSlice;
+class Dimension;
 class FuncRequest;
 class FuncStatus;
+class InsetIterator;
+class InsetCollapsable;
+class InsetLayout;
+class InsetList;
 class InsetMath;
 class InsetText;
 class LaTeXFeatures;
-class Color_color;
-class Cursor;
 class Lexer;
-class Text;
+class MathAtom;
 class MetricsInfo;
-class Dimension;
-class PainterInfo;
 class OutputParams;
+class PainterInfo;
+class ParConstIterator;
+class ParIterator;
+class Text;
 class TocList;
+class EmbeddedFile;
+class EmbeddedFiles;
 
 
 namespace graphics { class PreviewLoader; }
@@ -73,8 +80,6 @@ public:
 
        /// virtual base class destructor
        virtual ~Inset() {}
-       /// replicate ourselves
-       std::auto_ptr<Inset> clone() const;
 
        /// identification as math inset
        virtual InsetMath * asInsetMath() { return 0; }
@@ -84,6 +89,10 @@ public:
        virtual InsetText * asTextInset() { return 0; }
        /// is this inset based on the TextInset class?
        virtual InsetText const * asTextInset() const { return 0; }
+       /// is this inset based on the InsetCollapsable class?
+       virtual InsetCollapsable * asInsetCollapsable() { return 0; }
+       /// is this inset based on the InsetCollapsable class?
+       virtual InsetCollapsable const * asInsetCollapsable() const { return 0; }
        
        /// the real dispatcher
        void dispatch(Cursor & cur, FuncRequest & cmd);
@@ -116,7 +125,7 @@ public:
 
        /// compute the size of the object returned in dim
        /// \retval true if metrics changed.
-       virtual bool metrics(MetricsInfo & mi, Dimension & dim) const = 0;
+       virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
        /// draw inset and update (xo, yo)-cache
        virtual void draw(PainterInfo & pi, int x, int y) const = 0;
        /// draw inset selection if necessary
@@ -143,13 +152,21 @@ public:
        int yo(BufferView const & bv) const;
        /// set x/y drawing position cache if available
        virtual void setPosCache(PainterInfo const &, int, int) const;
+       ///
+       void setDimCache(MetricsInfo const &, Dimension const &) const;
        /// do we cover screen position x/y?
        virtual bool covers(BufferView const & bv, int x, int y) const;
        /// get the screen positions of the cursor (see note in Cursor.cpp)
        virtual void cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const;
 
+       ///
+       virtual bool isFreeSpacing() const { return false; }
+       ///
+       virtual bool allowEmpty() const { return false; }
+
        /// is this an inset that can be moved into?
+       /// FIXME: merge with editable()
        virtual bool isActive() const { return nargs() > 0; }
        /// Where should we go when we press the up or down cursor key?
        virtual bool idxUpDown(Cursor & cur, bool up) const;
@@ -198,6 +215,12 @@ public:
        /// is called when the mouse enter or leave this inset
        /// return true if this inset needs repaint
        virtual bool setMouseHover(bool) { return false; }
+       /// return true if this inset is hovered (under mouse)
+       /// This is by now only used by mathed to draw corners 
+       /// (Inset::drawMarkers() and Inset::drawMarkers2()).
+       /// Other insets do not have to redefine this function to 
+       /// return the correct status of mouseHovered.
+       virtual bool mouseHovered() const { return false; }
 
        /// request "external features"
        virtual void validate(LaTeXFeatures &) const {}
@@ -228,7 +251,7 @@ public:
        /** This enum indicates by which means the inset can be modified:
        - NOT_EDITABLE: the inset's content cannot be modified at all
          (e.g. printindex, insetspecialchar)
-       - IS_EDITABLE: content can be edited via dialog (e.g. bibtex, index, url)
+       - IS_EDITABLE: content can be edited via dialog (e.g. bibtex, index, href)
        - HIGHLY_EDITABLE: content can be edited on screen (normally means that
          insettext is contained, e.g. collapsables, tabular) */
        // FIXME: This has not yet been fully implemented to math insets
@@ -251,119 +274,8 @@ public:
        /// return true if the inset should be removed automatically
        virtual bool autoDelete() const;
 
-       /** This is not quite the correct place for this enum. I think
-           the correct would be to let each subclass of Inset declare
-           its own enum code. Actually the notion of an Inset::Code
-           should be avoided, but I am not sure how this could be done
-           in a cleaner way. */
-       enum Code {
-               ///
-               NO_CODE, // 0
-               ///
-               TOC_CODE,  // do these insets really need a code? (ale)
-               ///
-               QUOTE_CODE,
-               ///
-               MARK_CODE,
-               ///
-               REF_CODE,
-               ///
-               URL_CODE, // 5
-               ///
-               HTMLURL_CODE,
-               ///
-               SEPARATOR_CODE,
-               ///
-               ENDING_CODE,
-               ///
-               LABEL_CODE,
-               ///
-               NOTE_CODE, // 10
-               ///
-               ACCENT_CODE,
-               ///
-               MATH_CODE,
-               ///
-               INDEX_CODE,
-               ///
-               INCLUDE_CODE,
-               ///
-               GRAPHICS_CODE, // 15
-               ///
-               BIBITEM_CODE,
-               ///
-               BIBTEX_CODE,
-               ///
-               TEXT_CODE,
-               ///
-               ERT_CODE,
-               ///
-               FOOT_CODE, // 20
-               ///
-               MARGIN_CODE,
-               ///
-               FLOAT_CODE,
-               ///
-               WRAP_CODE,
-               ///
-               SPACE_CODE, // 25
-               ///
-               SPECIALCHAR_CODE,
-               ///
-               TABULAR_CODE,
-               ///
-               EXTERNAL_CODE,
-#if 0
-               ///
-               THEOREM_CODE,
-#endif
-               ///
-               CAPTION_CODE,
-               ///
-               MATHMACRO_CODE, // 30
-               ///
-               CITE_CODE,
-               ///
-               FLOAT_LIST_CODE,
-               ///
-               INDEX_PRINT_CODE,
-               ///
-               OPTARG_CODE, // 35
-               ///
-               ENVIRONMENT_CODE,
-               ///
-               HFILL_CODE,
-               ///
-               NEWLINE_CODE,
-               ///
-               LINE_CODE,
-               ///
-               BRANCH_CODE, // 40
-               ///
-               BOX_CODE,
-               ///
-               CHARSTYLE_CODE,
-               ///
-               VSPACE_CODE,
-               ///
-               MATHMACROARG_CODE,
-               ///
-               NOMENCL_CODE, // 45
-               ///
-               NOMENCL_PRINT_CODE,
-               ///
-               PAGEBREAK_CODE,
-               ///
-               LISTINGS_CODE
-       };
-
-       /** returns the Code corresponding to the \c name.
-        *  Eg, translate("branch") == BRANCH_CODE
-        */
-       static Code translate(std::string const & name);
-
        /// returns true if the inset can hold an inset of given type
-       virtual bool insetAllowed(Code) const { return false; }
+       virtual bool insetAllowed(InsetCode) const { return false; }
        /// if this inset has paragraphs should they be output all as default
        /// paragraphs with the default layout of the text class?
        virtual bool forceDefaultParagraphs(idx_type) const { return false; }
@@ -371,7 +283,9 @@ public:
        virtual bool hasFixedWidth() const { return false; }
 
        ///
-       virtual docstring name() const { return from_ascii("unknown"); }
+       virtual docstring name() const;
+       ///
+       virtual InsetLayout const & getLayout(BufferParams const & bp) const;
        /// used to toggle insets
        /// is the inset open?
        /// should this inset be handled like a normal charater
@@ -425,11 +339,22 @@ public:
         */
        virtual void addPreview(graphics::PreviewLoader &) const {}
        /// Add an entry to the TocList
-       virtual void addToToc(TocList &, Buffer const &) const {}
+       /// pit is the ParConstIterator of the paragraph containing the inset
+       virtual void addToToc(TocList &, Buffer const &, ParConstIterator const &) const {}
+       /// report files that can be embedded with the lyx file
+       virtual void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const {}
+       /// use embedded or external file after the embedding status of a file is changed
+       virtual void updateEmbeddedFile(Buffer const &, EmbeddedFile const &) {}
+       /// Fill keys with BibTeX information
+       virtual void fillWithBibKeys(Buffer const &,
+               BiblioInfo &, InsetIterator const &) const {}
+       /// Update the counters of this inset and of its contents
+       virtual void updateLabels(Buffer const &, ParIterator const &) {}
+
 
 public:
        /// returns LyX code associated with the inset. Used for TOC, ...)
-       virtual Code lyxCode() const { return NO_CODE; }
+       virtual InsetCode lyxCode() const { return NO_CODE; }
 
        /// -1: text mode, 1: math mode, 0 undecided
        enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
@@ -454,22 +379,15 @@ public:
        /// reject the changes within the inset
        virtual void rejectChanges(BufferParams const &) {};
 
-       /// inset width.
-       int width() const { return dim_.wid; }
-       /// inset ascent.
-       int ascent() const { return dim_.asc; }
-       /// inset descent.
-       int descent() const { return dim_.des; }
        ///
-       int scroll() const { return 0; }
+       virtual Dimension const dimension(BufferView const &) const;
        ///
-       void setBackgroundColor(Color_color);
+       int scroll() const { return 0; }
        ///
-       Color_color backgroundColor() const;
+       virtual ColorCode backgroundColor() const;
        ///
        enum CollapseStatus {
                Collapsed,
-               Inlined,
                Open
        };
        ///
@@ -477,14 +395,13 @@ public:
        //
        enum { TEXT_TO_INSET_OFFSET = 4 };
 
-       /// Signal for inset destruction.
-       /** This signal is emitted at the inset destruction for insets that
-       *   support this.
-       */
-       virtual boost::signal<void()> * destroyedSignal() { return 0; }
-
 protected:
-       Inset();
+       Inset() {}
+
+       /// replicate ourselves
+       friend class InsetList;
+       friend class MathAtom;
+       virtual Inset * clone() const = 0;
 
        /** The real dispatcher.
         *  Gets normally called from Cursor::dispatch(). Cursor::dispatch()
@@ -498,45 +415,8 @@ protected:
         *  \sa getStatus
         */
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
-
-       /// Cached dimensions of the inset.
-       mutable Dimension dim_;
-private:
-       virtual std::auto_ptr<Inset> doClone() const = 0;
-       /** We store the Color::color value as an int to get Color.h out
-        *  of the header file.
-        */
-       int background_color_;
-};
-
-
-/**
- * returns true if pointer argument is valid
- * and points to an editable inset
- */
-bool isEditableInset(Inset const * inset);
-
-
-/**
- * returns true if pointer argument is valid
- * and points to a highly editable inset
- */
-bool isHighlyEditableInset(Inset const * inset);
-
-/** \c Inset_code is a wrapper for Inset::Code.
- *  It can be forward-declared and passed as a function argument without
- *  having to expose Inset.h.
- */
-
-class Inset_code {
-       Inset::Code val_;
-public:
-       Inset_code(Inset::Code val) : val_(val) {}
-       operator Inset::Code() const { return val_; }
 };
 
-
-
 } // namespace lyx
 
 #endif