]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[lyx.git] / src / insets / Inset.cpp
index c57add10452d6ca1f01623ce7ae318c755bb3a09..0814a5042305557114a8d06bd40ef7b960544b3f 100644 (file)
 #include "Inset.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferView.h"
 #include "Color.h"
 #include "CoordCache.h"
 #include "Cursor.h"
 #include "debug.h"
-#include "debug.h"
 #include "Dimension.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "gettext.h"
-#include "LyXText.h"
+#include "Text.h"
+#include "TextClass.h"
 #include "MetricsInfo.h"
 #include "MetricsInfo.h"
 
 #include "frontends/Painter.h"
 
+#include "support/convert.h"
+
 #include <boost/current_function.hpp>
 
 #include <map>
@@ -85,8 +88,8 @@ static TranslatorMap const build_translator()
                InsetName("external", Inset::EXTERNAL_CODE),
                InsetName("caption", Inset::CAPTION_CODE),
                InsetName("mathmacro", Inset::MATHMACRO_CODE),
-               InsetName("cite", Inset::CITE_CODE),
-               InsetName("float_list", Inset::FLOAT_LIST_CODE),
+               InsetName("citation", Inset::CITE_CODE),
+               InsetName("floatlist", Inset::FLOAT_LIST_CODE),
                InsetName("index_print", Inset::INDEX_PRINT_CODE),
                InsetName("nomencl_print", Inset::NOMENCL_PRINT_CODE),
                InsetName("optarg", Inset::OPTARG_CODE),
@@ -96,9 +99,10 @@ static TranslatorMap const build_translator()
                InsetName("line", Inset::LINE_CODE),
                InsetName("branch", Inset::BRANCH_CODE),
                InsetName("box", Inset::BOX_CODE),
-               InsetName("charstyle", Inset::CHARSTYLE_CODE),
+               InsetName("flex", Inset::FLEX_CODE),
                InsetName("vspace", Inset::VSPACE_CODE),
                InsetName("mathmacroarg", Inset::MATHMACROARG_CODE),
+               InsetName("listings", Inset::LISTINGS_CODE),
        };
 
        std::size_t const insetnames_size =
@@ -114,28 +118,13 @@ static TranslatorMap const build_translator()
 }
 
 
-/// pretty arbitrary dimensions
 Inset::Inset()
-       : dim_(10, 10, 10), background_color_(Color::background)
-{}
-
-
-Inset::Inset(Inset const & inset)
-       : dim_(inset.dim_), background_color_(inset.background_color_)
 {}
 
 
-std::auto_ptr<Inset> Inset::clone() const
-{
-       std::auto_ptr<Inset> b = doClone();
-       BOOST_ASSERT(typeid(*b) == typeid(*this));
-       return b;
-}
-
-
-docstring Inset::insetName() const 
+Dimension const Inset::dimension(BufferView const & bv) const
 {
-       return from_ascii("unknown");
+       return bv.coordCache().getInsets().dim(this);
 }
 
 
@@ -278,7 +267,7 @@ void Inset::cursorPos(BufferView const & /*bv*/, CursorSlice const &,
 void Inset::metricsMarkers(Dimension & dim, int framesize) const
 {
        dim.wid += 2 * framesize;
-       dim.asc += framesize;
+       dim.des += framesize;
 }
 
 
@@ -292,11 +281,13 @@ void Inset::metricsMarkers2(Dimension & dim, int framesize) const
 
 void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
 {
-       Color::color pen_color = editing(pi.base.bv)?
-               Color::mathframe : Color::background;
+       Color::color pen_color = mouseHovered() || editing(pi.base.bv)?
+               Color::mathframe : Color::mathcorners;
+
+       Dimension const dim = dimension(*pi.base.bv);
 
-       int const t = x + width() - 1;
-       int const d = y + descent();
+       int const t = x + dim.width() - 1;
+       int const d = y + dim.descent();
        pi.pain.line(x, d - 3, x, d, pen_color);
        pi.pain.line(t, d - 3, t, d, pen_color);
        pi.pain.line(x, d, x + 3, d, pen_color);
@@ -307,12 +298,13 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
 
 void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
 {
-       Color::color pen_color = editing(pi.base.bv)?
-               Color::mathframe : Color::background;
+       Color::color pen_color = mouseHovered() || editing(pi.base.bv)?
+               Color::mathframe : Color::mathcorners;
 
        drawMarkers(pi, x, y);
-       int const t = x + width() - 1;
-       int const a = y - ascent();
+       Dimension const dim = dimension(*pi.base.bv);
+       int const t = x + dim.width() - 1;
+       int const a = y - dim.ascent();
        pi.pain.line(x, a + 3, x, a, pen_color);
        pi.pain.line(t, a + 3, t, a, pen_color);
        pi.pain.line(x, a, x + 3, a, pen_color);
@@ -341,35 +333,26 @@ int Inset::yo(BufferView const & bv) const
 
 bool Inset::covers(BufferView const & bv, int x, int y) const
 {
-       //lyxerr << "Inset::covers, x: " << x << " y: " << y
-       //      << " xo: " << xo(bv) << " yo: " << yo()
-       //      << " x1: " << xo(bv) << " x2: " << xo() + width()
-       //      << " y1: " << yo(bv) - ascent() << " y2: " << yo() + descent()
-       //      << std::endl;
-       return bv.coordCache().getInsets().has(this)
-                       && x >= xo(bv)
-                       && x <= xo(bv) + width()
-                       && y >= yo(bv) - ascent()
-                       && y <= yo(bv) + descent();
+       return bv.coordCache().getInsets().covers(this, x, y);
 }
 
 
-void Inset::dump() const
+InsetLayout const & Inset::getLayout(BufferParams const & bp) const
 {
-       Buffer buf("foo", 1);
-       write(buf, lyxerr);
+       return bp.getTextClass().insetlayout(name());  
 }
 
 
-void Inset::setBackgroundColor(Color_color color)
+void Inset::dump() const
 {
-       background_color_ = color;
+       Buffer buf("foo", 1);
+       write(buf, lyxerr);
 }
 
 
 Color_color Inset::backgroundColor() const
 {
-       return Color::color(background_color_);
+       return Color::background;
 }
 
 
@@ -380,6 +363,13 @@ void Inset::setPosCache(PainterInfo const & pi, int x, int y) const
 }
 
 
+void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
+{
+       mi.base.bv->coordCache().insets().add(this, dim);
+}
+
+
+
 /////////////////////////////////////////
 
 bool isEditableInset(Inset const * inset)