+extern bool quitting;
+
+class InsetName {
+public:
+ InsetName(string const & n, InsetCode c) : name(n), code(c) {}
+ string name;
+ InsetCode code;
+};
+
+
+typedef map<string, InsetCode> TranslatorMap;
+
+
+static TranslatorMap const build_translator()
+{
+ InsetName const insetnames[] = {
+ InsetName("toc", TOC_CODE),
+ InsetName("quote", QUOTE_CODE),
+ InsetName("ref", REF_CODE),
+ InsetName("href", HYPERLINK_CODE),
+ InsetName("separator", SEPARATOR_CODE),
+ InsetName("ending", ENDING_CODE),
+ InsetName("label", LABEL_CODE),
+ InsetName("note", NOTE_CODE),
+ InsetName("accent", ACCENT_CODE),
+ InsetName("math", MATH_CODE),
+ InsetName("index", INDEX_CODE),
+ InsetName("nomenclature", NOMENCL_CODE),
+ InsetName("include", INCLUDE_CODE),
+ InsetName("graphics", GRAPHICS_CODE),
+ InsetName("bibitem", BIBITEM_CODE),
+ InsetName("bibtex", BIBTEX_CODE),
+ InsetName("text", TEXT_CODE),
+ InsetName("ert", ERT_CODE),
+ InsetName("foot", FOOT_CODE),
+ InsetName("margin", MARGIN_CODE),
+ InsetName("float", FLOAT_CODE),
+ InsetName("wrap", WRAP_CODE),
+ InsetName("specialchar", SPECIALCHAR_CODE),
+ InsetName("tabular", TABULAR_CODE),
+ InsetName("external", EXTERNAL_CODE),
+ InsetName("caption", CAPTION_CODE),
+ InsetName("mathmacro", MATHMACRO_CODE),
+ InsetName("citation", CITE_CODE),
+ InsetName("floatlist", FLOAT_LIST_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("vspace", VSPACE_CODE),
+ InsetName("mathmacroarg", MATHMACROARG_CODE),
+ InsetName("listings", LISTINGS_CODE),
+ InsetName("info", INFO_CODE),
+ InsetName("collapsable", COLLAPSABLE_CODE),
+ InsetName("newpage", NEWPAGE_CODE),
+ };
+
+ size_t const insetnames_size =
+ sizeof(insetnames) / sizeof(insetnames[0]);
+
+ map<string, InsetCode> data;
+ for (size_t i = 0; i != insetnames_size; ++i) {
+ InsetName const & var = insetnames[i];
+ data[var.name] = var.code;
+ }
+
+ return data;
+}
+
+
+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(string const & name)
+{
+ static TranslatorMap const translator = build_translator();
+
+ TranslatorMap::const_iterator it = translator.find(name);
+ return it == translator.end() ? NO_CODE : it->second;
+}
+
+
+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);
+ cur.dispatched();
+ doDispatch(cur, cmd);
+}
+
+
+void Inset::doDispatch(Cursor & cur, FuncRequest &)
+{
+ cur.noUpdate();
+ cur.undispatched();
+}
+
+
+bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ // LFUN_INSET_APPLY is sent from the dialogs when the data should
+ // be applied. This is either changed to LFUN_INSET_MODIFY (if the
+ // dialog belongs to us) or LFUN_INSET_INSERT (if the dialog does
+ // not belong to us, i. e. the dialog was open, and the user moved
+ // the cursor in our inset) in LyXFunc::getStatus().
+ // Dialogs::checkStatus() ensures that the dialog is deactivated if
+ // LFUN_INSET_APPLY is disabled.
+
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY:
+ // Allow modification of our data.
+ // This needs to be handled in the doDispatch method of our
+ // instantiatable children.
+ flag.enabled(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);
+ return true;
+
+ default:
+ return false;
+ }
+}