2003-08-19 10:04:35 +00:00
|
|
|
/**
|
2007-04-29 13:39:47 +00:00
|
|
|
* \file Inset.cpp
|
2003-08-19 10:04:35 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2007-04-29 12:32:14 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
2007-04-29 12:32:14 +00:00
|
|
|
* \author Matthias Ettrich
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 10:04:35 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-19 10:04:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "Inset.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2008-03-10 15:30:32 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-06-06 03:11:56 +00:00
|
|
|
#include "BufferList.h"
|
2007-08-13 12:13:17 +00:00
|
|
|
#include "BufferParams.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-29 12:32:14 +00:00
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Dimension.h"
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2005-04-13 09:43:58 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-02-19 09:10:59 +00:00
|
|
|
#include "MetricsInfo.h"
|
2009-11-19 20:22:04 +00:00
|
|
|
#include "output_xhtml.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
#include "Text.h"
|
2007-08-13 12:13:17 +00:00
|
|
|
#include "TextClass.h"
|
2015-11-22 22:48:24 +00:00
|
|
|
#include "TocBackend.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2007-11-17 15:32:12 +00:00
|
|
|
#include "frontends/Application.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "frontends/Painter.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
#include "support/debug.h"
|
2008-02-28 07:58:00 +00:00
|
|
|
#include "support/docstream.h"
|
|
|
|
#include "support/ExceptionMessage.h"
|
2007-11-29 21:10:35 +00:00
|
|
|
#include "support/gettext.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lassert.h"
|
2005-07-18 21:19:23 +00:00
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
#include <map>
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2008-02-28 07:58:00 +00:00
|
|
|
using namespace lyx::support;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2004-03-30 12:36:33 +00:00
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class InsetName {
|
|
|
|
public:
|
2010-02-15 22:46:50 +00:00
|
|
|
InsetName(string const & n = string(), docstring const & dn = docstring())
|
|
|
|
: name(n), display_name(dn) {}
|
2007-12-12 19:28:07 +00:00
|
|
|
string name;
|
2010-02-15 22:46:50 +00:00
|
|
|
docstring display_name;
|
2004-03-30 12:36:33 +00:00
|
|
|
};
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
2010-02-15 22:46:50 +00:00
|
|
|
static InsetName insetnames[INSET_CODE_SIZE];
|
2004-03-30 12:36:33 +00:00
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
2010-05-03 20:08:31 +00:00
|
|
|
// This list should be kept in sync with the list of dialogs in
|
|
|
|
// src/frontends/qt4/GuiView.cpp, I.e., if a dialog goes with an
|
|
|
|
// inset, the dialog should have the same name as the inset.
|
|
|
|
// Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
|
|
|
|
// docs in LyXAction.cpp.
|
2010-02-15 22:46:50 +00:00
|
|
|
static void build_translator()
|
2004-03-30 12:36:33 +00:00
|
|
|
{
|
2010-02-15 22:46:50 +00:00
|
|
|
static bool passed = false;
|
|
|
|
if (passed)
|
|
|
|
return;
|
|
|
|
insetnames[TOC_CODE] = InsetName("toc");
|
|
|
|
insetnames[QUOTE_CODE] = InsetName("quote");
|
|
|
|
insetnames[REF_CODE] = InsetName("ref");
|
|
|
|
insetnames[HYPERLINK_CODE] = InsetName("href");
|
|
|
|
insetnames[SEPARATOR_CODE] = InsetName("separator");
|
|
|
|
insetnames[ENDING_CODE] = InsetName("ending");
|
|
|
|
insetnames[LABEL_CODE] = InsetName("label");
|
|
|
|
insetnames[NOTE_CODE] = InsetName("note");
|
|
|
|
insetnames[PHANTOM_CODE] = InsetName("phantom");
|
|
|
|
insetnames[ACCENT_CODE] = InsetName("accent");
|
|
|
|
insetnames[MATH_CODE] = InsetName("math");
|
|
|
|
insetnames[INDEX_CODE] = InsetName("index");
|
|
|
|
insetnames[NOMENCL_CODE] = InsetName("nomenclature");
|
|
|
|
insetnames[INCLUDE_CODE] = InsetName("include");
|
|
|
|
insetnames[GRAPHICS_CODE] = InsetName("graphics");
|
2010-02-23 21:24:24 +00:00
|
|
|
insetnames[BIBITEM_CODE] = InsetName("bibitem", _("Bibliography Entry"));
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[BIBTEX_CODE] = InsetName("bibtex");
|
|
|
|
insetnames[TEXT_CODE] = InsetName("text");
|
|
|
|
insetnames[ERT_CODE] = InsetName("ert", _("TeX Code"));
|
|
|
|
insetnames[FOOT_CODE] = InsetName("foot");
|
|
|
|
insetnames[MARGIN_CODE] = InsetName("margin");
|
|
|
|
insetnames[FLOAT_CODE] = InsetName("float", _("Float"));
|
|
|
|
insetnames[WRAP_CODE] = InsetName("wrap");
|
|
|
|
insetnames[SPECIALCHAR_CODE] = InsetName("specialchar");
|
2012-08-23 15:42:53 +00:00
|
|
|
insetnames[IPA_CODE] = InsetName("ipa");
|
|
|
|
insetnames[IPACHAR_CODE] = InsetName("ipachar");
|
|
|
|
insetnames[IPADECO_CODE] = InsetName("ipadeco");
|
2010-02-16 13:35:40 +00:00
|
|
|
insetnames[TABULAR_CODE] = InsetName("tabular", _("Table"));
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[EXTERNAL_CODE] = InsetName("external");
|
|
|
|
insetnames[CAPTION_CODE] = InsetName("caption");
|
|
|
|
insetnames[MATHMACRO_CODE] = InsetName("mathmacro");
|
|
|
|
insetnames[CITE_CODE] = InsetName("citation");
|
|
|
|
insetnames[FLOAT_LIST_CODE] = InsetName("floatlist");
|
|
|
|
insetnames[INDEX_PRINT_CODE] = InsetName("index_print");
|
|
|
|
insetnames[NOMENCL_PRINT_CODE] = InsetName("nomencl_print");
|
2010-06-04 22:44:58 +00:00
|
|
|
insetnames[ARG_CODE] = InsetName("optarg");
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[NEWLINE_CODE] = InsetName("newline");
|
|
|
|
insetnames[LINE_CODE] = InsetName("line");
|
2010-02-19 20:57:25 +00:00
|
|
|
insetnames[BRANCH_CODE] = InsetName("branch", _("Branch"));
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[BOX_CODE] = InsetName("box", _("Box"));
|
|
|
|
insetnames[FLEX_CODE] = InsetName("flex");
|
2010-02-21 09:28:33 +00:00
|
|
|
insetnames[SPACE_CODE] = InsetName("space", _("Horizontal Space"));
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[VSPACE_CODE] = InsetName("vspace", _("Vertical Space"));
|
|
|
|
insetnames[MATH_MACROARG_CODE] = InsetName("mathmacroarg");
|
|
|
|
insetnames[LISTINGS_CODE] = InsetName("listings");
|
|
|
|
insetnames[INFO_CODE] = InsetName("info", _("Info"));
|
2017-10-16 08:12:21 +00:00
|
|
|
insetnames[COLLAPSIBLE_CODE] = InsetName("collapsible");
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[NEWPAGE_CODE] = InsetName("newpage");
|
2010-11-21 17:00:12 +00:00
|
|
|
insetnames[SCRIPT_CODE] = InsetName("script");
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[CELL_CODE] = InsetName("tablecell");
|
|
|
|
insetnames[MATH_AMSARRAY_CODE] = InsetName("mathamsarray");
|
|
|
|
insetnames[MATH_ARRAY_CODE] = InsetName("matharray");
|
|
|
|
insetnames[MATH_BIG_CODE] = InsetName("mathbig");
|
|
|
|
insetnames[MATH_BOLDSYMBOL_CODE] = InsetName("mathboldsymbol");
|
|
|
|
insetnames[MATH_BOX_CODE] = InsetName("mathbox");
|
|
|
|
insetnames[MATH_BRACE_CODE] = InsetName("mathbrace");
|
2012-01-23 01:49:49 +00:00
|
|
|
insetnames[MATH_CANCEL_CODE] = InsetName("mathcancel");
|
|
|
|
insetnames[MATH_CANCELTO_CODE] = InsetName("mathcancelto");
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[MATH_CASES_CODE] = InsetName("mathcases");
|
|
|
|
insetnames[MATH_CHAR_CODE] = InsetName("mathchar");
|
|
|
|
insetnames[MATH_COLOR_CODE] = InsetName("mathcolor");
|
|
|
|
insetnames[MATH_COMMENT_CODE] = InsetName("mathcomment");
|
|
|
|
insetnames[MATH_DECORATION_CODE] = InsetName("mathdecoration");
|
|
|
|
insetnames[MATH_DELIM_CODE] = InsetName("mathdelim");
|
|
|
|
insetnames[MATH_DIFF_CODE] = InsetName("mathdiff");
|
|
|
|
insetnames[MATH_DOTS_CODE] = InsetName("mathdots");
|
|
|
|
insetnames[MATH_ENSUREMATH_CODE] = InsetName("mathensuremath");
|
|
|
|
insetnames[MATH_ENV_CODE] = InsetName("mathenv");
|
|
|
|
insetnames[MATH_EXFUNC_CODE] = InsetName("mathexfunc");
|
|
|
|
insetnames[MATH_EXINT_CODE] = InsetName("mathexint");
|
|
|
|
insetnames[MATH_FONT_CODE] = InsetName("mathfont");
|
|
|
|
insetnames[MATH_FONTOLD_CODE] = InsetName("mathfontold");
|
|
|
|
insetnames[MATH_FRAC_CODE] = InsetName("mathfrac");
|
|
|
|
insetnames[MATH_GRID_CODE] = InsetName("mathgrid");
|
|
|
|
insetnames[MATH_CODE] = InsetName("math");
|
|
|
|
insetnames[MATH_HULL_CODE] = InsetName("mathhull");
|
|
|
|
insetnames[MATH_KERN_CODE] = InsetName("mathkern");
|
|
|
|
insetnames[MATH_LEFTEQN_CODE] = InsetName("mathlefteqn");
|
|
|
|
insetnames[MATH_LIM_CODE] = InsetName("mathlim");
|
|
|
|
insetnames[MATH_MATRIX_CODE] = InsetName("mathmatrix");
|
|
|
|
insetnames[MATH_MBOX_CODE] = InsetName("mathmbox");
|
|
|
|
insetnames[MATH_NEST_CODE] = InsetName("mathnest");
|
|
|
|
insetnames[MATH_NUMBER_CODE] = InsetName("mathnumber");
|
|
|
|
insetnames[MATH_OVERSET_CODE] = InsetName("mathoverset");
|
|
|
|
insetnames[MATH_PAR_CODE] = InsetName("mathpar");
|
|
|
|
insetnames[MATH_PHANTOM_CODE] = InsetName("mathphantom");
|
|
|
|
insetnames[MATH_REF_CODE] = InsetName("mathref");
|
|
|
|
insetnames[MATH_ROOT_CODE] = InsetName("mathroot");
|
|
|
|
insetnames[MATH_SCRIPT_CODE] = InsetName("mathscript");
|
|
|
|
insetnames[MATH_SIZE_CODE] = InsetName("mathsize");
|
2010-02-21 09:28:33 +00:00
|
|
|
insetnames[MATH_SPACE_CODE] = InsetName("mathspace", _("Horizontal Math Space"));
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[MATH_SPECIALCHAR_CODE] = InsetName("mathspecialchar");
|
|
|
|
insetnames[MATH_SPLIT_CODE] = InsetName("mathsplit");
|
|
|
|
insetnames[MATH_SQRT_CODE] = InsetName("mathsqrt");
|
|
|
|
insetnames[MATH_STACKREL_CODE] = InsetName("mathstackrel");
|
|
|
|
insetnames[MATH_STRING_CODE] = InsetName("mathstring");
|
|
|
|
insetnames[MATH_SUBSTACK_CODE] = InsetName("mathsubstack");
|
|
|
|
insetnames[MATH_SYMBOL_CODE] = InsetName("mathsymbol");
|
|
|
|
insetnames[MATH_TABULAR_CODE] = InsetName("mathtabular");
|
|
|
|
insetnames[MATH_UNDERSET_CODE] = InsetName("mathunderset");
|
|
|
|
insetnames[MATH_UNKNOWN_CODE] = InsetName("mathunknown");
|
|
|
|
insetnames[MATH_XARROW_CODE] = InsetName("mathxarrow");
|
|
|
|
insetnames[MATH_XYMATRIX_CODE] = InsetName("mathxymatrix");
|
2010-09-19 22:12:06 +00:00
|
|
|
insetnames[MATH_DIAGRAM_CODE] = InsetName("mathdiagram");
|
2010-02-15 22:46:50 +00:00
|
|
|
insetnames[MATH_MACRO_CODE] = InsetName("mathmacro");
|
|
|
|
|
|
|
|
passed = true;
|
2004-03-30 12:36:33 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Inset::setBuffer(Buffer & buffer)
|
|
|
|
{
|
|
|
|
buffer_ = &buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-05 13:47:13 +00:00
|
|
|
void Inset::resetBuffer()
|
|
|
|
{
|
|
|
|
buffer_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
Buffer & Inset::buffer()
|
|
|
|
{
|
2008-02-28 07:58:00 +00:00
|
|
|
if (!buffer_) {
|
|
|
|
odocstringstream s;
|
2011-03-28 22:33:04 +00:00
|
|
|
string const iname = insetName(lyxCode());
|
|
|
|
LYXERR0("Inset: " << this << " LyX Code: " << lyxCode()
|
|
|
|
<< " name: " << iname);
|
2015-10-15 18:52:28 +00:00
|
|
|
s << "LyX Code: " << lyxCode() << " name: " << from_ascii(iname);
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(false);
|
2017-07-03 17:53:14 +00:00
|
|
|
throw ExceptionMessage(BufferException,
|
2008-02-28 07:58:00 +00:00
|
|
|
from_ascii("Inset::buffer_ member not initialized!"), s.str());
|
|
|
|
}
|
|
|
|
return *buffer_;
|
2008-02-27 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Buffer const & Inset::buffer() const
|
|
|
|
{
|
|
|
|
return const_cast<Inset *>(this)->buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-08 18:57:42 +00:00
|
|
|
bool Inset::isBufferLoaded() const
|
2008-06-06 03:11:56 +00:00
|
|
|
{
|
2008-07-23 12:13:41 +00:00
|
|
|
return buffer_ && theBufferList().isLoaded(buffer_);
|
2008-06-06 03:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-08 19:07:05 +00:00
|
|
|
bool Inset::isBufferValid() const
|
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
return buffer_
|
2010-03-08 19:07:05 +00:00
|
|
|
&& (isBufferLoaded() || buffer_->isClone());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring Inset::layoutName() const
|
2007-11-01 22:17:22 +00:00
|
|
|
{
|
|
|
|
return from_ascii("unknown");
|
|
|
|
}
|
2007-04-22 21:40:10 +00:00
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
bool Inset::isFreeSpacing() const
|
2009-07-13 15:57:08 +00:00
|
|
|
{
|
|
|
|
return getLayout().isFreeSpacing();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Inset::allowEmpty() const
|
|
|
|
{
|
|
|
|
return getLayout().isKeepEmpty();
|
|
|
|
}
|
|
|
|
|
2010-10-26 01:10:19 +00:00
|
|
|
|
2009-07-13 15:57:08 +00:00
|
|
|
bool Inset::forceLTR() const
|
|
|
|
{
|
2009-07-14 21:14:39 +00:00
|
|
|
return getLayout().forceLTR();
|
2009-07-13 15:57:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-10 15:30:32 +00:00
|
|
|
|
2010-10-26 01:10:19 +00:00
|
|
|
bool Inset::isInToc() const
|
|
|
|
{
|
|
|
|
return getLayout().isInToc();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 18:53:38 +00:00
|
|
|
docstring Inset::toolTip(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-04 18:38:47 +00:00
|
|
|
void Inset::forOutliner(docstring &, size_t const, bool const) const
|
2010-12-20 21:55:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string Inset::contextMenu(BufferView const &, int, int) const
|
2010-11-29 21:27:25 +00:00
|
|
|
{
|
|
|
|
return contextMenuName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string Inset::contextMenuName() const
|
2007-12-26 12:40:58 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return string();
|
2007-12-26 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const Inset::dimension(BufferView const & bv) const
|
2007-09-21 20:39:47 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
return bv.coordCache().getInsets().dim(this);
|
2007-09-21 20:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
InsetCode insetCode(string const & name)
|
2004-03-30 12:36:33 +00:00
|
|
|
{
|
2010-02-15 22:46:50 +00:00
|
|
|
build_translator();
|
|
|
|
for (int i = 1; i != int(INSET_CODE_SIZE); ++i) {
|
|
|
|
if (insetnames[i].name == name)
|
|
|
|
return InsetCode(i);
|
|
|
|
}
|
|
|
|
return NO_CODE;
|
2004-03-30 12:36:33 +00:00
|
|
|
}
|
2003-02-18 11:47:16 +00:00
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
string insetName(InsetCode c)
|
2007-10-19 17:22:55 +00:00
|
|
|
{
|
2010-02-15 22:46:50 +00:00
|
|
|
build_translator();
|
|
|
|
return insetnames[c].name;
|
|
|
|
}
|
2007-10-19 17:22:55 +00:00
|
|
|
|
2010-02-15 22:46:50 +00:00
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
docstring insetDisplayName(InsetCode c)
|
2010-02-15 22:46:50 +00:00
|
|
|
{
|
|
|
|
build_translator();
|
|
|
|
return insetnames[c].display_name;
|
2007-10-19 17:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
|
2003-10-17 18:01:15 +00:00
|
|
|
{
|
2009-07-20 18:21:26 +00:00
|
|
|
if (buffer_ == 0) {
|
|
|
|
lyxerr << "Unassigned buffer_ member in Inset::dispatch()" << std::endl;
|
2017-07-03 17:53:14 +00:00
|
|
|
lyxerr << "LyX Code: " << lyxCode() << " name: "
|
2010-03-08 20:22:37 +00:00
|
|
|
<< insetName(lyxCode()) << std::endl;
|
2009-07-20 18:21:26 +00:00
|
|
|
} else if (cur.buffer() != buffer_)
|
|
|
|
lyxerr << "cur.buffer() != buffer_ in Inset::dispatch()" << std::endl;
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.screenUpdateFlags(Update::Force | Update::FitCursor);
|
2004-08-13 14:56:06 +00:00
|
|
|
cur.dispatched();
|
2004-11-24 21:58:42 +00:00
|
|
|
doDispatch(cur, cmd);
|
2003-10-17 18:01:15 +00:00
|
|
|
}
|
2003-02-18 11:47:16 +00:00
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
2010-02-16 13:35:40 +00:00
|
|
|
bool Inset::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
InsetCode const code = lyxCode();
|
|
|
|
switch (code){
|
|
|
|
case ERT_CODE:
|
|
|
|
case FLOAT_CODE:
|
|
|
|
case BOX_CODE:
|
2010-02-23 21:24:24 +00:00
|
|
|
case BIBITEM_CODE:
|
2010-02-19 20:57:25 +00:00
|
|
|
case BRANCH_CODE:
|
2010-02-16 13:35:40 +00:00
|
|
|
case INFO_CODE:
|
2010-02-21 09:28:33 +00:00
|
|
|
case MATH_SPACE_CODE:
|
|
|
|
case SPACE_CODE:
|
2010-02-18 08:28:46 +00:00
|
|
|
case TABULAR_CODE:
|
2010-02-16 13:35:40 +00:00
|
|
|
case VSPACE_CODE:
|
|
|
|
bv->showDialog(insetName(code));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-13 14:44:53 +00:00
|
|
|
void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
|
2003-02-18 11:47:16 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-04-10 12:38:32 +00:00
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
// if the derived inset did not explicitly handle mouse_release,
|
|
|
|
// we assume we request the settings dialog
|
2009-04-22 20:55:13 +00:00
|
|
|
if (!cur.selection() && cmd.button() == mouse_button::button1
|
2016-02-02 16:17:10 +00:00
|
|
|
&& clickable(cur.bv(), cmd.x(), cmd.y()) && hasSettings()) {
|
2009-04-10 12:38:32 +00:00
|
|
|
FuncRequest tmpcmd(LFUN_INSET_SETTINGS);
|
|
|
|
dispatch(cur, tmpcmd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-04-09 23:17:20 +00:00
|
|
|
case LFUN_INSET_SETTINGS:
|
2009-04-22 20:55:13 +00:00
|
|
|
if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
|
|
|
|
showInsetDialog(&cur.bv());
|
|
|
|
cur.dispatched();
|
|
|
|
} else
|
|
|
|
cur.undispatched();
|
2009-04-09 23:17:20 +00:00
|
|
|
break;
|
2009-04-10 12:38:32 +00:00
|
|
|
|
2008-05-13 14:44:53 +00:00
|
|
|
default:
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2008-05-13 14:44:53 +00:00
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
2003-02-18 11:47:16 +00:00
|
|
|
}
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
|
2005-04-13 09:43:58 +00:00
|
|
|
FuncStatus & flag) const
|
2004-02-20 17:19:53 +00:00
|
|
|
{
|
2005-04-13 09:43:58 +00:00
|
|
|
// 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
|
2010-02-09 16:11:13 +00:00
|
|
|
// the cursor in our inset) in lyx::getStatus().
|
2005-04-13 09:43:58 +00:00
|
|
|
// Dialogs::checkStatus() ensures that the dialog is deactivated if
|
|
|
|
// LFUN_INSET_APPLY is disabled.
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-13 09:43:58 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2005-05-17 11:11:45 +00:00
|
|
|
// Allow modification of our data.
|
2005-04-13 09:43:58 +00:00
|
|
|
// This needs to be handled in the doDispatch method of our
|
|
|
|
// instantiatable children.
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-05-17 11:11:45 +00:00
|
|
|
return true;
|
2005-04-13 09:43:58 +00:00
|
|
|
|
|
|
|
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.
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2005-04-13 09:43:58 +00:00
|
|
|
return true;
|
|
|
|
|
2009-04-09 23:17:20 +00:00
|
|
|
case LFUN_INSET_SETTINGS:
|
2009-04-22 20:55:13 +00:00
|
|
|
if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
|
|
|
|
bool const enable = hasSettings();
|
|
|
|
flag.setEnabled(enable);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-21 12:56:34 +00:00
|
|
|
|
2010-04-16 15:42:33 +00:00
|
|
|
case LFUN_IN_MATHMACROTEMPLATE:
|
2017-07-05 12:31:28 +00:00
|
|
|
// By default we're not in a InsetMathMacroTemplate inset
|
2010-04-16 15:42:33 +00:00
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
2009-04-09 23:17:20 +00:00
|
|
|
|
2012-08-21 12:56:34 +00:00
|
|
|
case LFUN_IN_IPA:
|
|
|
|
// By default we're not in an IPA inset
|
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
|
2005-04-13 09:43:58 +00:00
|
|
|
default:
|
2008-05-13 14:44:53 +00:00
|
|
|
break;
|
2005-04-13 09:43:58 +00:00
|
|
|
}
|
2008-05-13 14:44:53 +00:00
|
|
|
return false;
|
2004-02-20 17:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
void Inset::edit(Cursor &, bool, EntryDirection)
|
2003-11-06 16:43:12 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::INSETS, "edit left/right");
|
2003-11-06 16:43:12 +00:00
|
|
|
}
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * Inset::editXY(Cursor &, int x, int y)
|
2003-11-04 12:36:59 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR(Debug::INSETS, "x: " << x << " y: " << y);
|
2005-07-15 00:39:44 +00:00
|
|
|
return this;
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset::idx_type Inset::index(row_type row, col_type col) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (row != 0)
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("illegal row: " << row);
|
2004-01-26 10:13:15 +00:00
|
|
|
if (col != 0)
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("illegal col: " << col);
|
2004-01-26 10:13:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::idxBetween(idx_type idx, idx_type from, idx_type to) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return from <= idx && idx <= to;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::idxUpDown(Cursor &, bool) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Inset::docbook(odocstream &, OutputParams const &) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 20:22:04 +00:00
|
|
|
docstring Inset::xhtml(XHTMLStream & xs, OutputParams const &) const
|
|
|
|
{
|
|
|
|
xs << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2009-06-05 17:44:35 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::directWrite() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
bool Inset::editable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Inset::hasSettings() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2009-04-22 20:55:13 +00:00
|
|
|
return false;
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 20:55:13 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::autoDelete() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Inset::cursorPos(BufferView const & /*bv*/, CursorSlice const &,
|
2006-10-17 16:23:27 +00:00
|
|
|
bool, int & x, int & y) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0("Inset::cursorPos called directly");
|
2004-01-30 11:41:12 +00:00
|
|
|
x = 100;
|
|
|
|
y = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Inset::metricsMarkers(Dimension & dim, int framesize) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2004-08-13 15:08:25 +00:00
|
|
|
dim.wid += 2 * framesize;
|
2007-05-19 19:45:55 +00:00
|
|
|
dim.des += framesize;
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Inset::metricsMarkers2(Dimension & dim, int framesize) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2004-08-13 15:08:25 +00:00
|
|
|
dim.wid += 2 * framesize;
|
|
|
|
dim.asc += framesize;
|
|
|
|
dim.des += framesize;
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-17 09:21:38 +00:00
|
|
|
void Inset::drawBackground(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
if (pi.full_repaint && backgroundColor(pi) == Color_none)
|
|
|
|
return;
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
pi.pain.fillRectangle(x, y - dim.asc, dim.wid, dim.asc + dim.des,
|
|
|
|
pi.backgroundColor(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-07 21:36:42 +00:00
|
|
|
void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2010-04-30 14:47:46 +00:00
|
|
|
ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)?
|
2007-10-25 12:41:02 +00:00
|
|
|
Color_mathframe : Color_mathcorners;
|
2007-06-07 21:36:42 +00:00
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
|
|
|
int const t = x + dim.width() - 1;
|
|
|
|
int const d = y + dim.descent();
|
2007-06-07 21:36:42 +00:00
|
|
|
pi.pain.line(x, d - 3, x, d, pen_color);
|
|
|
|
pi.pain.line(t, d - 3, t, d, pen_color);
|
|
|
|
pi.pain.line(x, d, x + 3, d, pen_color);
|
|
|
|
pi.pain.line(t - 3, d, t, d, pen_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2010-04-30 14:47:46 +00:00
|
|
|
ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)?
|
2007-10-25 12:41:02 +00:00
|
|
|
Color_mathframe : Color_mathcorners;
|
2007-06-07 21:36:42 +00:00
|
|
|
|
|
|
|
drawMarkers(pi, x, y);
|
2007-09-21 20:39:47 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
int const t = x + dim.width() - 1;
|
|
|
|
int const a = y - dim.ascent();
|
2007-06-07 21:36:42 +00:00
|
|
|
pi.pain.line(x, a + 3, x, a, pen_color);
|
|
|
|
pi.pain.line(t, a + 3, t, a, pen_color);
|
|
|
|
pi.pain.line(x, a, x + 3, a, pen_color);
|
|
|
|
pi.pain.line(t - 3, a, t, a, pen_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-22 14:38:43 +00:00
|
|
|
bool Inset::editing(BufferView const * bv) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
|
|
|
return bv->cursor().isInside(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
int Inset::xo(BufferView const & bv) const
|
2004-08-14 14:03:42 +00:00
|
|
|
{
|
2006-10-13 16:44:44 +00:00
|
|
|
return bv.coordCache().getInsets().x(this);
|
2004-08-14 14:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
int Inset::yo(BufferView const & bv) const
|
2004-08-14 14:03:42 +00:00
|
|
|
{
|
2006-10-13 16:44:44 +00:00
|
|
|
return bv.coordCache().getInsets().y(this);
|
2004-08-14 14:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
bool Inset::covers(BufferView const & bv, int x, int y) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2007-09-24 08:05:49 +00:00
|
|
|
return bv.coordCache().getInsets().covers(this, x, y);
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 00:28:22 +00:00
|
|
|
InsetLayout const & Inset::getLayout() const
|
2007-08-13 12:13:17 +00:00
|
|
|
{
|
2010-02-09 11:16:17 +00:00
|
|
|
if (!buffer_)
|
|
|
|
return DocumentClass::plainInsetLayout();
|
2011-03-28 22:33:04 +00:00
|
|
|
return buffer().params().documentClass().insetLayout(layoutName());
|
2007-08-13 12:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 20:25:25 +00:00
|
|
|
bool Inset::undefined() const
|
|
|
|
{
|
|
|
|
docstring const & n = getLayout().name();
|
|
|
|
return n.empty() || n == DocumentClass::plainInsetLayout().name();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
void Inset::dump() const
|
2004-02-02 17:32:56 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
write(lyxerr);
|
2004-02-02 17:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-17 14:09:37 +00:00
|
|
|
ColorCode Inset::backgroundColor(PainterInfo const & /*pi*/) const
|
2007-04-22 21:40:10 +00:00
|
|
|
{
|
2008-10-25 10:47:38 +00:00
|
|
|
return Color_none;
|
2007-04-22 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 06:46:52 +00:00
|
|
|
ColorCode Inset::labelColor() const
|
|
|
|
{
|
|
|
|
return Color_foreground;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-17 15:32:12 +00:00
|
|
|
Buffer const * Inset::updateFrontend() const
|
|
|
|
{
|
2010-12-03 21:00:15 +00:00
|
|
|
//FIXME (Abdel 03/12/10): see bugs #6814 and #6949
|
2010-12-03 21:03:36 +00:00
|
|
|
// If the Buffer is null and we end up here this is most probably because we
|
2010-12-03 21:00:15 +00:00
|
|
|
// are in the CutAndPaste stack. See InsetGraphics, RenderGraphics and
|
|
|
|
// RenderPreview.
|
|
|
|
if (!buffer_)
|
|
|
|
return 0;
|
2008-02-27 21:51:29 +00:00
|
|
|
return theApp() ? theApp()->updateInset(this) : 0;
|
2007-11-17 15:32:12 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
|
2014-02-10 21:06:32 +00:00
|
|
|
bool Inset::resetFontEdit() const
|
|
|
|
{
|
|
|
|
return getLayout().resetsFont() || !inheritFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
docstring Inset::completionPrefix(Cursor const &) const
|
2008-03-15 00:02:41 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|