* 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.
*/
#include "Inset.h"
+#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/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/ExceptionMessage.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include <map>
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),
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("listings", LISTINGS_CODE),
InsetName("info", INFO_CODE),
InsetName("collapsable", COLLAPSABLE_CODE),
InsetName("newpage", NEWPAGE_CODE),
+ InsetName("tablecell", CELL_CODE)
};
size_t const insetnames_size =
{
if (!buffer_) {
odocstringstream s;
- s << "LyX Code: " << lyxCode();
- throw ExceptionMessage(WarningException,
+ lyxerr << "LyX Code: " << lyxCode() << " name: " << name() << std::endl;
+ s << "LyX Code: " << lyxCode() << " name: " << name();
+ LASSERT(false, /**/);
+ throw ExceptionMessage(BufferException,
from_ascii("Inset::buffer_ member not initialized!"), s.str());
}
return *buffer_;
}
+bool Inset::isBufferValid() const
+{
+ return buffer_ && theBufferList().isLoaded(buffer_);
+}
+
+
docstring Inset::name() const
{
return from_ascii("unknown");
}
+void Inset::initView()
+{
+ if (isLabeled())
+ buffer().updateLabels();
+}
+
+
docstring Inset::toolTip(BufferView const &, int, int) const
{
return docstring();
void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
{
+ LASSERT(cur.buffer() == &buffer(), return);
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;
+ }
}
// 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;
}
}
+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;
}
-InsetLayout const & Inset::getLayout(BufferParams const & bp) const
+InsetLayout const & Inset::getLayout() const
{
- return bp.documentClass().insetLayout(name());
+ return buffer().params().documentClass().insetLayout(name());
}
ColorCode Inset::backgroundColor() const
{
- return Color_background;
+ return Color_none;
+}
+
+
+ColorCode Inset::labelColor() const
+{
+ return Color_foreground;
}
return theApp() ? theApp()->updateInset(this) : 0;
}
+
+docstring Inset::completionPrefix(Cursor const &) const
+{
+ return docstring();
+}
+
} // namespace lyx