]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Remove all BufferParam arguments in InsetXXX methods (since insets know about their...
[lyx.git] / src / insets / Inset.cpp
index d83fc6629ddc029ae2a6f23ae2a2e683ce9f073b..dbefc1279dbab1415c91227004d7931343676bf0 100644 (file)
@@ -4,10 +4,10 @@
  * 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
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -18,6 +18,7 @@
 
 #include "buffer_funcs.h"
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "Text.h"
 #include "TextClass.h"
 
-#include "frontends/Painter.h"
 #include "frontends/Application.h"
+#include "frontends/Painter.h"
 
-#include "support/lassert.h"
-#include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/ExceptionMessage.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 
 #include <map>
 
@@ -69,6 +69,7 @@ static TranslatorMap const build_translator()
                InsetName("ending", ENDING_CODE),
                InsetName("label", LABEL_CODE),
                InsetName("note", NOTE_CODE),
+               InsetName("phantom", PHANTOM_CODE),
                InsetName("accent", ACCENT_CODE),
                InsetName("math", MATH_CODE),
                InsetName("index", INDEX_CODE),
@@ -93,7 +94,6 @@ static TranslatorMap const build_translator()
                InsetName("index_print", INDEX_PRINT_CODE),
                InsetName("nomencl_print", NOMENCL_PRINT_CODE),
                InsetName("optarg", OPTARG_CODE),
-               InsetName("environment", ENVIRONMENT_CODE),
                InsetName("newline", NEWLINE_CODE),
                InsetName("line", LINE_CODE),
                InsetName("branch", BRANCH_CODE),
@@ -148,6 +148,12 @@ Buffer const & Inset::buffer() const
 }
 
 
+bool Inset::isBufferValid() const
+{
+       return buffer_ && theBufferList().isLoaded(buffer_);
+}
+
+
 docstring Inset::name() const
 {
        return from_ascii("unknown");
@@ -157,7 +163,7 @@ docstring Inset::name() const
 void Inset::initView()
 {
        if (isLabeled())
-               lyx::updateLabels(buffer());
+               buffer().updateLabels();
 }
 
 
@@ -204,6 +210,7 @@ string insetName(InsetCode c)
 
 void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
 {
+       LASSERT(cur.buffer() == &buffer(), return);
        cur.updateFlags(Update::Force | Update::FitCursor);
        cur.dispatched();
        doDispatch(cur, cmd);
@@ -213,10 +220,24 @@ void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
 void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
 {
        switch (cmd.action) {
-       case LFUN_INSET_TOGGLE:
-               edit(cur, true);
-               cur.dispatched();
+       case LFUN_MOUSE_RELEASE:
+               // if the derived inset did not explicitly handle mouse_release,
+               // we assume we request the settings dialog
+               if (!cur.selection() && cmd.button() == mouse_button::button1
+                         && hasSettings()) {
+                       FuncRequest tmpcmd(LFUN_INSET_SETTINGS);
+                       dispatch(cur, tmpcmd);
+               }
+               break;
+
+       case LFUN_INSET_SETTINGS:
+               if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
+                       showInsetDialog(&cur.bv());
+                       cur.dispatched();
+               } else
+                       cur.undispatched();
                break;
+
        default:
                cur.noUpdate();
                cur.undispatched();
@@ -251,10 +272,15 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
                flag.setEnabled(false);
                return true;
 
-       case LFUN_INSET_TOGGLE:
-               // remove this if we dissociate toggle from edit.
-               flag.setEnabled(editable() == IS_EDITABLE);
-               return true;
+       case LFUN_INSET_SETTINGS:
+               if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
+                       bool const enable = hasSettings();
+                       flag.setEnabled(enable);
+                       return true;
+               } else {
+                       flag.setEnabled(false);
+                       return false;
+               }
 
        default:
                break;
@@ -304,18 +330,31 @@ int Inset::docbook(odocstream &, OutputParams const &) const
 }
 
 
+docstring Inset::xhtml(odocstream & od, OutputParams const &) const
+{
+       od << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
+       return docstring();
+}
+
 bool Inset::directWrite() const
 {
        return false;
 }
 
 
-Inset::EDITABLE Inset::editable() const
+bool Inset::editable() const
 {
-       return NOT_EDITABLE;
+       return false;
 }
 
 
+bool Inset::hasSettings() const
+{
+       return false;
+}
+
+
+
 bool Inset::autoDelete() const
 {
        return false;
@@ -410,9 +449,9 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 }
 
 
-InsetLayout const & Inset::getLayout(BufferParams const & bp) const
+InsetLayout const & Inset::getLayout() const
 {
-       return bp.documentClass().insetLayout(name());  
+       return buffer().params().documentClass().insetLayout(name());
 }
 
 
@@ -424,7 +463,13 @@ void Inset::dump() const
 
 ColorCode Inset::backgroundColor() const
 {
-       return Color_background;
+       return Color_none;
+}
+
+
+ColorCode Inset::labelColor() const
+{
+       return Color_foreground;
 }