]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
* Inset: Prepare for an eventual merge of updateLabels() and addToToc()
[lyx.git] / src / insets / Inset.cpp
index 1876f5ec3fb05ca549a3360307758eddce5266d6..0cfb10cdd3e074dd2057529624b56f83a2b2a4e6 100644 (file)
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
-#include "Color.h"
 #include "CoordCache.h"
 #include "Cursor.h"
-#include "debug.h"
 #include "Dimension.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "gettext.h"
 #include "Text.h"
 #include "TextClass.h"
 #include "MetricsInfo.h"
 #include "MetricsInfo.h"
 
 #include "frontends/Painter.h"
+#include "frontends/Application.h"
 
 #include "support/convert.h"
-
-#include <boost/current_function.hpp>
+#include "support/debug.h"
+#include "support/gettext.h"
 
 #include <map>
-#include <typeinfo>
 
+using namespace std;
 
 namespace lyx {
 
+extern bool quitting;
+
 class InsetName {
 public:
-       InsetName(std::string const & n, InsetCode c)
-               : name(n), code(c) {}
-       std::string name;
+       InsetName(string const & n, InsetCode c) : name(n), code(c) {}
+       string name;
        InsetCode code;
 };
 
 
-typedef std::map<std::string, InsetCode> TranslatorMap;
+typedef map<string, InsetCode> TranslatorMap;
 
 
 static TranslatorMap const build_translator()
@@ -63,8 +62,7 @@ static TranslatorMap const build_translator()
                InsetName("toc", TOC_CODE),
                InsetName("quote", QUOTE_CODE),
                InsetName("ref", REF_CODE),
-               InsetName("url", URL_CODE),
-               InsetName("htmlurl", HTMLURL_CODE),
+               InsetName("href", HYPERLINK_CODE),
                InsetName("separator", SEPARATOR_CODE),
                InsetName("ending", ENDING_CODE),
                InsetName("label", LABEL_CODE),
@@ -104,13 +102,15 @@ static TranslatorMap const build_translator()
                InsetName("mathmacroarg", MATHMACROARG_CODE),
                InsetName("listings", LISTINGS_CODE),
                InsetName("info", INFO_CODE),
+               InsetName("collapsable", COLLAPSABLE_CODE),
+               InsetName("newpage", NEWPAGE_CODE),
        };
 
-       std::size_t const insetnames_size =
+       size_t const insetnames_size =
                sizeof(insetnames) / sizeof(insetnames[0]);
 
-       std::map<std::string, InsetCode> data;
-       for (std::size_t i = 0; i != insetnames_size; ++i) {
+       map<string, InsetCode> data;
+       for (size_t i = 0; i != insetnames_size; ++i) {
                InsetName const & var = insetnames[i];
                data[var.name] = var.code;
        }
@@ -119,8 +119,22 @@ static TranslatorMap const build_translator()
 }
 
 
-Inset::Inset()
-{}
+docstring Inset::name() const
+{
+       return from_ascii("unknown");
+}
+
+
+docstring Inset::toolTip(BufferView const &, int, int) const
+{
+       return docstring();
+}
+
+
+docstring Inset::contextMenu(BufferView const &, int, int) const
+{
+       return docstring();
+}
 
 
 Dimension const Inset::dimension(BufferView const & bv) const
@@ -129,7 +143,7 @@ Dimension const Inset::dimension(BufferView const & bv) const
 }
 
 
-InsetCode insetCode(std::string const & name)
+InsetCode insetCode(string const & name)
 {
        static TranslatorMap const translator = build_translator();
 
@@ -138,6 +152,20 @@ InsetCode insetCode(std::string const & name)
 }
 
 
+string insetName(InsetCode c) 
+{
+       static TranslatorMap const translator = build_translator();
+
+       TranslatorMap::const_iterator it =  translator.begin();
+       TranslatorMap::const_iterator end = translator.end();
+       for (; it != end; ++it) {
+               if (it->second == c)
+                       return it->first;
+       }
+       return string();
+}
+
+
 void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
 {
        cur.updateFlags(Update::Force | Update::FitCursor);
@@ -185,18 +213,15 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
 }
 
 
-void Inset::edit(Cursor &, bool)
+void Inset::edit(Cursor &, bool, EntryDirection)
 {
-       LYXERR(Debug::INSETS) << BOOST_CURRENT_FUNCTION
-                             << ": edit left/right" << std::endl;
+       LYXERR(Debug::INSETS, "edit left/right");
 }
 
 
 Inset * Inset::editXY(Cursor &, int x, int y)
 {
-       LYXERR(Debug::INSETS) << BOOST_CURRENT_FUNCTION
-                             << ": x=" << x << " y= " << y
-                             << std::endl;
+       LYXERR(Debug::INSETS, "x: " << x << " y: " << y);
        return this;
 }
 
@@ -204,11 +229,9 @@ Inset * Inset::editXY(Cursor &, int x, int y)
 Inset::idx_type Inset::index(row_type row, col_type col) const
 {
        if (row != 0)
-               lyxerr << BOOST_CURRENT_FUNCTION
-                      << ": illegal row: " << row << std::endl;
+               LYXERR0("illegal row: " << row);
        if (col != 0)
-               lyxerr << BOOST_CURRENT_FUNCTION
-                      << ": illegal col: " << col << std::endl;
+               LYXERR0("illegal col: " << col);
        return 0;
 }
 
@@ -259,7 +282,7 @@ docstring const Inset::editMessage() const
 void Inset::cursorPos(BufferView const & /*bv*/, CursorSlice const &,
                bool, int & x, int & y) const
 {
-       lyxerr << "Inset::cursorPos called directly" << std::endl;
+       LYXERR0("Inset::cursorPos called directly");
        x = 100;
        y = 100;
 }
@@ -282,8 +305,8 @@ void Inset::metricsMarkers2(Dimension & dim, int framesize) const
 
 void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
 {
-       Color::color pen_color = mouseHovered() || editing(pi.base.bv)?
-               Color::mathframe : Color::mathcorners;
+       ColorCode pen_color = mouseHovered() || editing(pi.base.bv)?
+               Color_mathframe : Color_mathcorners;
 
        Dimension const dim = dimension(*pi.base.bv);
 
@@ -299,8 +322,8 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
 
 void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
 {
-       Color::color pen_color = mouseHovered() || editing(pi.base.bv)?
-               Color::mathframe : Color::mathcorners;
+       ColorCode pen_color = mouseHovered() || editing(pi.base.bv)?
+               Color_mathframe : Color_mathcorners;
 
        drawMarkers(pi, x, y);
        Dimension const dim = dimension(*pi.base.bv);
@@ -314,7 +337,7 @@ void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
 }
 
 
-bool Inset::editing(BufferView * bv) const
+bool Inset::editing(BufferView const * bv) const
 {
        return bv->cursor().isInside(this);
 }
@@ -351,15 +374,15 @@ void Inset::dump() const
 }
 
 
-Color_color Inset::backgroundColor() const
+ColorCode Inset::backgroundColor() const
 {
-       return Color::background;
+       return Color_background;
 }
 
 
 void Inset::setPosCache(PainterInfo const & pi, int x, int y) const
 {
-       //lyxerr << "Inset:: position cache to " << x << " " << y << std::endl;
+       //LYXERR("Inset: set position cache to " << x << " " << y);
        pi.base.bv->coordCache().insets().add(this, x, y);
 }
 
@@ -369,4 +392,12 @@ void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
        mi.base.bv->coordCache().insets().add(this, dim);
 }
 
+
+Buffer const * Inset::updateFrontend() const
+{
+       if (quitting)
+               return 0;
+       return theApp()->updateInset(this);
+}
+
 } // namespace lyx