]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Introduce BufferException so that we don't crash if a problem affects only current...
[lyx.git] / src / insets / Inset.cpp
index 58e9aa1ce2b25016bf147371c068f01982e72369..b82f264874319cce97d63cbaccb1b46f616b38f9 100644 (file)
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "MetricsInfo.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 "support/debug.h"
+#include "support/docstream.h"
+#include "support/ExceptionMessage.h"
 #include "support/gettext.h"
 
 #include <map>
 
+using namespace std;
+using namespace lyx::support;
 
 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()
@@ -108,7 +109,7 @@ static TranslatorMap const build_translator()
        size_t const insetnames_size =
                sizeof(insetnames) / sizeof(insetnames[0]);
 
-       std::map<std::string, InsetCode> data;
+       map<string, InsetCode> data;
        for (size_t i = 0; i != insetnames_size; ++i) {
                InsetName const & var = insetnames[i];
                data[var.name] = var.code;
@@ -118,19 +119,55 @@ static TranslatorMap const build_translator()
 }
 
 
+void Inset::setBuffer(Buffer & buffer)
+{
+       buffer_ = &buffer;
+}
+
+
+Buffer & Inset::buffer()
+{
+       if (!buffer_) {
+               odocstringstream s;
+               s << "LyX Code: " << lyxCode() << " name: " << name();
+               throw ExceptionMessage(BufferException, 
+                       from_ascii("Inset::buffer_ member not initialized!"), s.str());
+       }
+       return *buffer_;
+}
+
+
+Buffer const & Inset::buffer() const
+{
+       return const_cast<Inset *>(this)->buffer();
+}
+
+
 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
 {
        return bv.coordCache().getInsets().dim(this);
 }
 
 
-InsetCode insetCode(std::string const & name)
+InsetCode insetCode(string const & name)
 {
        static TranslatorMap const translator = build_translator();
 
@@ -139,7 +176,7 @@ InsetCode insetCode(std::string const & name)
 }
 
 
-std::string insetName(InsetCode c) 
+string insetName(InsetCode c) 
 {
        static TranslatorMap const translator = build_translator();
 
@@ -149,7 +186,7 @@ std::string insetName(InsetCode c)
                if (it->second == c)
                        return it->first;
        }
-       return std::string();
+       return string();
 }
 
 
@@ -200,7 +237,7 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
 }
 
 
-void Inset::edit(Cursor &, bool)
+void Inset::edit(Cursor &, bool, EntryDirection)
 {
        LYXERR(Debug::INSETS, "edit left/right");
 }
@@ -235,8 +272,7 @@ bool Inset::idxUpDown(Cursor &, bool) const
 }
 
 
-int Inset::docbook(Buffer const &,
-       odocstream &, OutputParams const &) const
+int Inset::docbook(odocstream &, OutputParams const &) const
 {
        return 0;
 }
@@ -260,7 +296,7 @@ bool Inset::autoDelete() const
 }
 
 
-docstring const Inset::editMessage() const
+docstring Inset::editMessage() const
 {
        return _("Opened inset");
 }
@@ -324,7 +360,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);
 }
@@ -350,14 +386,13 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 
 InsetLayout const & Inset::getLayout(BufferParams const & bp) const
 {
-       return bp.getTextClass().insetlayout(name());  
+       return bp.documentClass().insetLayout(name());  
 }
 
 
 void Inset::dump() const
 {
-       Buffer buf("foo", 1);
-       write(buf, lyxerr);
+       write(lyxerr);
 }
 
 
@@ -382,9 +417,7 @@ void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
 
 Buffer const * Inset::updateFrontend() const
 {
-       if (quitting)
-               return 0;
-       return theApp()->updateInset(this);
+       return theApp() ? theApp()->updateInset(this) : 0;
 }
 
 } // namespace lyx