#include "InsetText.h"
#include "insets/InsetArgument.h"
+#include "insets/InsetLayout.h"
#include "buffer_funcs.h"
#include "Buffer.h"
#include "InsetList.h"
#include "Intl.h"
#include "Language.h"
+#include "Layout.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "lyxfind.h"
#include "frontends/alert.h"
#include "frontends/Painter.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
}
+void InsetText::setMacrocontextPositionRecursive(DocIterator const & pos)
+{
+ text_.setMacrocontextPosition(pos);
+
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ ParagraphList::const_iterator pend = paragraphs().end();
+ for (; pit != pend; ++pit) {
+ InsetList::const_iterator iit = pit->insetList().begin();
+ InsetList::const_iterator end = pit->insetList().end();
+ for (; iit != end; ++iit) {
+ if (InsetText * txt = iit->inset->asInsetText()) {
+ DocIterator ppos(pos);
+ ppos.push_back(CursorSlice(*txt));
+ iit->inset->asInsetText()->setMacrocontextPositionRecursive(ppos);
+ }
+ }
+ }
+}
+
+
void InsetText::clear()
{
ParagraphList & pars = paragraphs();
void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
{
- LYXERR(Debug::ACTION, "InsetText::doDispatch()"
- << " [ cmd.action() = " << cmd.action() << ']');
+ LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
- if (getLayout().isPassThru()) {
+#if 0
+// FIXME: This code does not seem to be necessary anymore
+// Remove for 2.1 if no counter-evidence is found.
+ if (isPassThru() && lyxCode() != ARG_CODE) {
// Force any new text to latex_language FIXME: This
// should only be necessary in constructor, but new
// paragraphs that are created by pressing enter at
cur.current_font.setLanguage(latex_language);
cur.real_current_font.setLanguage(latex_language);
}
+#endif
switch (cmd.action()) {
case LFUN_PASTE:
return target_inset;
}
+ case LFUN_ARGUMENT_INSERT: {
+ string const arg = cmd.getArg(0);
+ if (arg.empty()) {
+ status.setEnabled(false);
+ return true;
+ }
+ if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
+ return text_.getStatus(cur, cmd, status);
+
+ Layout::LaTeXArgMap args = getLayout().args();
+ Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
+ if (lait != args.end()) {
+ status.setEnabled(true);
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ for (; pit != paragraphs().end(); ++pit) {
+ InsetList::const_iterator it = pit->insetList().begin();
+ InsetList::const_iterator end = pit->insetList().end();
+ for (; it != end; ++it) {
+ if (it->inset->lyxCode() == ARG_CODE) {
+ InsetArgument const * ins =
+ static_cast<InsetArgument const *>(it->inset);
+ if (ins->name() == arg) {
+ // we have this already
+ status.setEnabled(false);
+ return true;
+ }
+ }
+ }
+ }
+ } else
+ status.setEnabled(false);
+ return true;
+ }
+
default:
// Dispatch only to text_ if the cursor is inside
// the text_. It is not for context menus (bug 5797).
ParagraphList::iterator par = paragraphs().begin();
ParagraphList::iterator const end = paragraphs().end();
while (par != end) {
- if (par->isPassThru()) {
+ if (par->isPassThru())
par->resetFonts(font);
+ if (!par->allowParagraphCustomization())
par->params().clear();
- ++par;
- }
+ ++par;
}
}
}
-int InsetText::latex(odocstream & os, OutputParams const & runparams) const
+void InsetText::latex(otexstream & os, OutputParams const & runparams) const
{
// This implements the standard way of handling the LaTeX
// output of a text inset, either a command or an
// environment. Standard collapsable insets should not
// redefine this, non-standard ones may call this.
InsetLayout const & il = getLayout();
- int rows = 0;
if (!il.latexname().empty()) {
if (il.latextype() == InsetLayout::COMMAND) {
// FIXME UNICODE
if (runparams.moving_arg)
os << "\\protect";
os << '\\' << from_utf8(il.latexname());
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
if (!il.latexparam().empty())
os << from_utf8(il.latexparam());
os << '{';
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
- os << "%\n\\begin{" << from_utf8(il.latexname()) << "}\n";
+ if (il.isDisplay())
+ os << breakln;
+ else
+ os << safebreakln;
+ if (runparams.lastid != -1)
+ os.texrow().start(runparams.lastid,
+ runparams.lastpos);
+ os << "\\begin{" << from_utf8(il.latexname()) << "}";
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
if (!il.latexparam().empty())
os << from_utf8(il.latexparam());
- rows += 2;
+ os << '\n';
}
+ } else {
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
+ if (!il.latexparam().empty())
+ os << from_utf8(il.latexparam());
}
+
+ if (!il.leftdelim().empty())
+ os << il.leftdelim();
+
OutputParams rp = runparams;
- if (il.isPassThru())
+ if (isPassThru())
rp.pass_thru = true;
if (il.isNeedProtect())
rp.moving_arg = true;
rp.par_end = paragraphs().size();
// Output the contents of the inset
- TexRow texrow;
- latexParagraphs(buffer(), text_, os, texrow, rp);
- rows += texrow.rows();
+ latexParagraphs(buffer(), text_, os, rp);
runparams.encoding = rp.encoding;
+ if (!il.rightdelim().empty())
+ os << il.rightdelim();
+
if (!il.latexname().empty()) {
if (il.latextype() == InsetLayout::COMMAND) {
os << "}";
+ if (!il.postcommandargs().empty())
+ getArgs(os, runparams, true);
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
- os << "%\n\\end{" << from_utf8(il.latexname()) << "}\n";
- rows += 2;
+ // A comment environment doesn't need a % before \n\end
+ if (il.isDisplay() || runparams.inComment)
+ os << breakln;
+ else
+ os << safebreakln;
+ os << "\\end{" << from_utf8(il.latexname()) << "}\n";
+ if (!il.isDisplay())
+ os.protectSpace(true);
}
}
- return rows;
}
// if so, try to close fonts, etc.
// There are probably limits to how well we can do here, though, and we will
// have to rely upon users not putting footnotes inside noun-type insets.
-docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & runparams,
+docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
XHTMLOptions opts) const
{
+ // we will always want to output all our paragraphs when we are
+ // called this way.
+ OutputParams runparams = rp;
+ runparams.par_begin = 0;
+ runparams.par_end = text().paragraphs().size();
+
if (undefined()) {
xhtmlParagraphs(text_, buffer(), xs, runparams);
return docstring();
InsetLayout const & il = getLayout();
if (opts & WriteOuterTag)
xs << html::StartTag(il.htmltag(), il.htmlattr());
+
if ((opts & WriteLabel) && !il.counter().empty()) {
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & cntrs = bp.documentClass().counters();
if (opts & WriteInnerTag)
xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
- OutputParams ours = runparams;
+
+ // we will eventually lose information about the containing inset
if (!il.isMultiPar() || opts == JustText)
- ours.html_make_pars = false;
- xhtmlParagraphs(text_, buffer(), xs, ours);
+ runparams.html_make_pars = false;
+ if (il.isPassThru())
+ runparams.pass_thru = true;
+
+ xhtmlParagraphs(text_, buffer(), xs, runparams);
+
if (opts & WriteInnerTag)
xs << html::EndTag(il.htmlinnertag());
+
if (opts & WriteOuterTag)
xs << html::EndTag(il.htmltag());
+
return docstring();
}
+void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
+ bool const post) const
+{
+ OutputParams runparams = runparams_in;
+ runparams.local_font =
+ ¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
+ if (isPassThru())
+ runparams.pass_thru = true;
+ if (post)
+ latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
+ else
+ latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
+}
+
void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
}
+bool InsetText::insetAllowed(InsetCode code) const
+{
+ switch (code) {
+ // Arguments are also allowed in PassThru insets
+ case ARG_CODE:
+ return true;
+ default:
+ return !isPassThru();
+ }
+}
+
+
void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
{
ParIterator it2 = it;
arginset = inset.asInsetText();
}
// now the toc entry for the paragraph
- int const toclevel = par.layout().toclevel;
+ int const toclevel = text().getTocLevel(pit);
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
// insert this into the table of contents
docstring tocstring;
}
-docstring InsetText::contextMenu(BufferView const &, int, int) const
+string InsetText::contextMenu(BufferView const &, int, int) const
{
- docstring context_menu = contextMenuName();
+ string context_menu = contextMenuName();
if (context_menu != InsetText::contextMenuName())
context_menu += ";" + InsetText::contextMenuName();
return context_menu;
}
-docstring InsetText::contextMenuName() const
+string InsetText::contextMenuName() const
{
- return from_ascii("context-edit");
+ return "context-edit";
}