]> 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 033764b307f055b44b962cf6f0da6fefe664492a..0814a5042305557114a8d06bd40ef7b960544b3f 100644 (file)
@@ -23,7 +23,6 @@
 #include "CoordCache.h"
 #include "Cursor.h"
 #include "debug.h"
-#include "debug.h"
 #include "Dimension.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
@@ -36,6 +35,8 @@
 
 #include "frontends/Painter.h"
 
+#include "support/convert.h"
+
 #include <boost/current_function.hpp>
 
 #include <map>
@@ -87,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),
@@ -98,7 +99,7 @@ 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),
@@ -117,12 +118,16 @@ static TranslatorMap const build_translator()
 }
 
 
-/// pretty arbitrary dimensions
 Inset::Inset()
-       : dim_(10, 10, 10)
 {}
 
 
+Dimension const Inset::dimension(BufferView const & bv) const
+{
+       return bv.coordCache().getInsets().dim(this);
+}
+
+
 Inset::Code Inset::translate(std::string const & name)
 {
        static TranslatorMap const translator = build_translator();
@@ -279,8 +284,10 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
        Color::color pen_color = mouseHovered() || editing(pi.base.bv)?
                Color::mathframe : Color::mathcorners;
 
-       int const t = x + width() - 1;
-       int const d = y + descent();
+       Dimension const dim = dimension(*pi.base.bv);
+
+       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);
@@ -295,8 +302,9 @@ void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
                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);
@@ -325,16 +333,7 @@ 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);
 }
 
 
@@ -364,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)