]> git.lyx.org Git - lyx.git/blobdiff - src/insets/Inset.cpp
Restore XHTML output for InsetListings.
[lyx.git] / src / insets / Inset.cpp
index d77f4b10ec2a5a0fe5fefd4f26a17ab84091e245..82a5426cbe43147d609dec5f3dc8dfbea2a9c61a 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.
  */
@@ -16,7 +16,9 @@
 
 #include "Inset.h"
 
+#include "buffer_funcs.h"
 #include "Buffer.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "CoordCache.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "LyX.h" // quitting
 #include "MetricsInfo.h"
+#include "output_xhtml.h"
 #include "Text.h"
 #include "TextClass.h"
 
-#include "frontends/Painter.h"
 #include "frontends/Application.h"
+#include "frontends/Painter.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>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -65,6 +70,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),
@@ -89,19 +95,72 @@ 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("hfill", HFILL_CODE),
                InsetName("newline", NEWLINE_CODE),
                InsetName("line", LINE_CODE),
                InsetName("branch", BRANCH_CODE),
                InsetName("box", BOX_CODE),
                InsetName("flex", FLEX_CODE),
+               InsetName("space", SPACE_CODE),
                InsetName("vspace", VSPACE_CODE),
-               InsetName("mathmacroarg", MATHMACROARG_CODE),
+               InsetName("mathmacroarg", MATH_MACROARG_CODE),
                InsetName("listings", LISTINGS_CODE),
                InsetName("info", INFO_CODE),
                InsetName("collapsable", COLLAPSABLE_CODE),
                InsetName("newpage", NEWPAGE_CODE),
+               InsetName("tablecell", CELL_CODE),
+               InsetName("mathamsarray", MATH_AMSARRAY_CODE),
+               InsetName("matharray", MATH_ARRAY_CODE),
+               InsetName("mathbig", MATH_BIG_CODE),
+               InsetName("mathboldsymbol", MATH_BOLDSYMBOL_CODE),
+               InsetName("mathbox", MATH_BOX_CODE),
+               InsetName("mathbrace", MATH_BRACE_CODE),
+               InsetName("mathcases", MATH_CASES_CODE),
+               InsetName("mathchar", MATH_CHAR_CODE),
+               InsetName("mathcolor", MATH_COLOR_CODE),
+               InsetName("mathcomment", MATH_COMMENT_CODE),
+               InsetName("mathdecoration", MATH_DECORATION_CODE),
+               InsetName("mathdelim", MATH_DELIM_CODE),
+               InsetName("mathdiff", MATH_DIFF_CODE),
+               InsetName("mathdots", MATH_DOTS_CODE),
+               InsetName("mathensuremath", MATH_ENSUREMATH_CODE),
+               InsetName("mathenv", MATH_ENV_CODE),
+               InsetName("mathexfunc", MATH_EXFUNC_CODE),
+               InsetName("mathexint", MATH_EXINT_CODE),
+               InsetName("mathfont", MATH_FONT_CODE),
+               InsetName("mathfontold", MATH_FONTOLD_CODE),
+               InsetName("mathfrac", MATH_FRAC_CODE),
+               InsetName("mathgrid", MATH_GRID_CODE),
+               InsetName("math", MATH_CODE),
+               InsetName("mathhull", MATH_HULL_CODE),
+               InsetName("mathkern", MATH_KERN_CODE),
+               InsetName("mathlefteqn", MATH_LEFTEQN_CODE),
+               InsetName("mathlim", MATH_LIM_CODE),
+               InsetName("mathmatrix", MATH_MATRIX_CODE),
+               InsetName("mathmbox", MATH_MBOX_CODE),
+               InsetName("mathnest", MATH_NEST_CODE),
+               InsetName("mathnumber", MATH_NUMBER_CODE),
+               InsetName("mathoverset", MATH_OVERSET_CODE),
+               InsetName("mathpar", MATH_PAR_CODE),
+               InsetName("mathphantom", MATH_PHANTOM_CODE),
+               InsetName("mathref", MATH_REF_CODE),
+               InsetName("mathroot", MATH_ROOT_CODE),
+               InsetName("mathscript", MATH_SCRIPT_CODE),
+               InsetName("mathsize", MATH_SIZE_CODE),
+               InsetName("mathspace", MATH_SPACE_CODE),
+               InsetName("mathspecialchar", MATH_SPECIALCHAR_CODE),
+               InsetName("mathsplit", MATH_SPLIT_CODE),
+               InsetName("mathsqrt", MATH_SQRT_CODE),
+               InsetName("mathstackrel", MATH_STACKREL_CODE),
+               InsetName("mathstring", MATH_STRING_CODE),
+               InsetName("mathsubstack", MATH_SUBSTACK_CODE),
+               InsetName("mathsymbol", MATH_SYMBOL_CODE),
+               InsetName("mathtabular", MATH_TABULAR_CODE),
+               InsetName("mathunderset", MATH_UNDERSET_CODE),
+               InsetName("mathunknown", MATH_UNKNOWN_CODE),
+               InsetName("mathxarrow", MATH_XARROW_CODE),
+               InsetName("mathxyarrow", MATH_XYARROW_CODE),
+               InsetName("mathxymatrix", MATH_XYMATRIX_CODE),
+               InsetName("mathmacro", MATH_MACRO_CODE),
        };
 
        size_t const insetnames_size =
@@ -117,12 +176,70 @@ static TranslatorMap const build_translator()
 }
 
 
+void Inset::setBuffer(Buffer & buffer)
+{
+       buffer_ = &buffer;
+}
+
+
+Buffer & Inset::buffer()
+{
+       if (!buffer_) {
+               odocstringstream s;
+               lyxerr << "Inset: " << this
+                                       << " LyX Code: " << lyxCode()
+                                       << " name: " << insetName(lyxCode())
+                                       << std::endl;
+               s << "LyX Code: " << lyxCode() << " name: " << name();
+               LASSERT(false, /**/);
+               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();
+}
+
+
+bool Inset::isBufferValid() const
+{
+       return buffer_ && theBufferList().isLoaded(buffer_);
+}
+
+
 docstring Inset::name() const
 {
        return from_ascii("unknown");
 }
 
 
+bool Inset::isFreeSpacing() const 
+{
+       return getLayout().isFreeSpacing();
+}
+
+
+bool Inset::allowEmpty() const
+{
+       return getLayout().isKeepEmpty();
+}
+
+bool Inset::forceLTR() const
+{
+       return getLayout().forceLTR();
+}
+
+void Inset::initView()
+{
+       if (isLabeled())
+               buffer().updateLabels();
+}
+
+
 docstring Inset::toolTip(BufferView const &, int, int) const
 {
        return docstring();
@@ -166,16 +283,43 @@ string insetName(InsetCode c)
 
 void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
 {
+       if (buffer_ == 0) {
+               lyxerr << "Unassigned buffer_ member in Inset::dispatch()" << std::endl;
+               lyxerr << "LyX Code: " << lyxCode() << " name: " << insetName(lyxCode()) << std::endl;
+       } else if (cur.buffer() != buffer_)
+               lyxerr << "cur.buffer() != buffer_ in Inset::dispatch()" << std::endl;
        cur.updateFlags(Update::Force | Update::FitCursor);
        cur.dispatched();
        doDispatch(cur, cmd);
 }
 
 
-void Inset::doDispatch(Cursor & cur, FuncRequest &)
+void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
 {
-       cur.noUpdate();
-       cur.undispatched();
+       switch (cmd.action) {
+       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();
+               break;
+       }
 }
 
 
@@ -195,19 +339,30 @@ bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
                // Allow modification of our data.
                // This needs to be handled in the doDispatch method of our
                // instantiatable children.
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        case LFUN_INSET_INSERT:
                // Don't allow insertion of new insets.
                // Every inset that wants to allow new insets from open
                // dialogs needs to override this.
-               flag.enabled(false);
+               flag.setEnabled(false);
                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:
-               return false;
+               break;
        }
+       return false;
 }
 
 
@@ -246,34 +401,46 @@ bool Inset::idxUpDown(Cursor &, bool) const
 }
 
 
-int Inset::docbook(Buffer const &,
-       odocstream &, OutputParams const &) const
+int Inset::docbook(odocstream &, OutputParams const &) const
 {
        return 0;
 }
 
 
+docstring Inset::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       xs << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
+       return docstring();
+}
+
+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::autoDelete() const
+bool Inset::hasSettings() const
 {
        return false;
 }
 
 
-docstring const Inset::editMessage() const
+
+bool Inset::autoDelete() const
 {
-       return _("Opened inset");
+       return false;
 }
 
 
@@ -359,22 +526,34 @@ 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 buffer().params().documentClass().insetLayout(name());
+}
+
+
+bool Inset::undefined() const
 {
-       return bp.getTextClass().insetLayout(name());  
+       docstring const & n = getLayout().name();
+       return n.empty() || n == DocumentClass::plainInsetLayout().name();
 }
 
 
 void Inset::dump() const
 {
-       Buffer buf("foo", 1);
-       write(buf, lyxerr);
+       write(lyxerr);
 }
 
 
 ColorCode Inset::backgroundColor() const
 {
-       return Color_background;
+       return Color_none;
+}
+
+
+ColorCode Inset::labelColor() const
+{
+       return Color_foreground;
 }
 
 
@@ -393,9 +572,13 @@ 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;
+}
+
+
+docstring Inset::completionPrefix(Cursor const &) const 
+{
+       return docstring();
 }
 
 } // namespace lyx