* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Jürgen Vigna
+ * \author Jürgen Vigna
*
* Full author contact details are available in file CREDITS.
*/
#include "ErrorList.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
+#include "InsetCaption.h"
#include "InsetList.h"
#include "Intl.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_docbook.h"
#include "output_latex.h"
+#include "output_xhtml.h"
#include "OutputParams.h"
#include "output_plaintext.h"
#include "paragraph_funcs.h"
/////////////////////////////////////////////////////////////////////
-InsetText::InsetText(Buffer const & buf)
+InsetText::InsetText(Buffer const & buf, UsePlain type)
: drawFrame_(false), frame_color_(Color_insetframe)
{
setBuffer(const_cast<Buffer &>(buf));
- initParagraphs();
+ initParagraphs(type);
}
}
-void InsetText::initParagraphs()
+void InsetText::initParagraphs(UsePlain type)
{
LASSERT(paragraphs().empty(), /**/);
paragraphs().push_back(Paragraph());
Paragraph & ourpar = paragraphs().back();
ourpar.setInsetOwner(this);
- ourpar.setDefaultLayout(buffer_->params().documentClass());
+ DocumentClass const & dc = buffer_->params().documentClass();
+ if (type == DefaultLayout)
+ ourpar.setDefaultLayout(dc);
+ else
+ ourpar.setPlainLayout(dc);
}
// Hand font through to contained lyxtext:
tm.font_.fontInfo() = mi.base.font;
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+
+ // This can happen when a layout has a left and right margin,
+ // and the view is made very narrow. We can't do better than
+ // to draw it partly out of view (bug 5890).
+ if (mi.base.textwidth < 1)
+ mi.base.textwidth = 1;
+
if (hasFixedWidth())
tm.metrics(mi, dim, mi.base.textwidth);
else
{
LYXERR(Debug::ACTION, "InsetText::doDispatch()"
<< " [ cmd.action = " << cmd.action << ']');
- text_.dispatch(cur, cmd);
+
+ // Dispatch only to text_ if the cursor is inside
+ // the text_. It is not for context menus (bug 5797).
+ if (cur.text() == &text_)
+ text_.dispatch(cur, cmd);
+ else
+ cur.undispatched();
+
+ if (!cur.result().dispatched())
+ Inset::doDispatch(cur, cmd);
}
status.setEnabled(allowParagraphCustomization());
return true;
default:
- return text_.getStatus(cur, cmd, status);
+ // Dispatch only to text_ if the cursor is inside
+ // the text_. It is not for context menus (bug 5797).
+ bool ret = false;
+ if (cur.text() == &text_)
+ ret = text_.getStatus(cur, cmd, status);
+
+ if (!ret)
+ ret = Inset::getStatus(cur, cmd, status);
+ return ret;
}
}
}
-void InsetText::acceptChanges(BufferParams const & bparams)
+void InsetText::acceptChanges()
{
- text_.acceptChanges(bparams);
+ text_.acceptChanges(buffer().params());
}
-void InsetText::rejectChanges(BufferParams const & bparams)
+void InsetText::rejectChanges()
{
- text_.rejectChanges(bparams);
+ text_.rejectChanges(buffer().params());
}
}
+docstring InsetText::xhtml(odocstream & os, OutputParams const & runparams) const
+{
+ xhtmlParagraphs(paragraphs(), buffer(), os, runparams);
+ return docstring();
+}
+
+
void InsetText::validate(LaTeXFeatures & features) const
{
for_each(paragraphs().begin(), paragraphs().end(),
{
ParIterator it2 = it;
it2.forwardPos();
- LASSERT(&it2.inset() == this && it2.pit() == 0, /**/);
+ LASSERT(&it2.inset() == this && it2.pit() == 0, return);
if (producesOutput())
- lyx::updateLabels(buffer(), it2);
+ buffer().updateLabels(it2);
else {
- DocumentClass const & tclass = buffer().params().documentClass();
+ DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
Counters const savecnt = tclass.counters();
- lyx::updateLabels(buffer(), it2);
+ buffer().updateLabels(it2);
tclass.counters() = savecnt;
}
}
break;
}
}
- /// now the toc entry for the paragraph
+ // now the toc entry for the paragraph
int const toclevel = par.layout().toclevel;
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
dit.pos() = 0;
bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
{
- if (cur.buffer().isClean())
+ if (buffer().isClean())
return Inset::notifyCursorLeaves(old, cur);
// find text inset in old cursor
LASSERT(&insetCur.inset() == this, /**/);
// update the old paragraph's words
- insetCur.paragraph().updateWords(insetCur.top());
+ insetCur.paragraph().updateWords();
return Inset::notifyCursorLeaves(old, cur);
}
bool InsetText::completionSupported(Cursor const & cur) const
{
- Cursor const & bvCur = cur.bv().cursor();
- if (&bvCur.inset() != this)
- return false;
+ //LASSERT(&cur.bv().cursor().inset() != this, return false);
return text_.completionSupported(cur);
}
}
+InsetCaption const * InsetText::getCaptionInset() const
+{
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ for (; pit != paragraphs().end(); ++pit) {
+ InsetList::const_iterator it = pit->insetList().begin();
+ for (; it != pit->insetList().end(); ++it) {
+ Inset & inset = *it->inset;
+ if (inset.lyxCode() == CAPTION_CODE) {
+ InsetCaption const * ins =
+ static_cast<InsetCaption const *>(it->inset);
+ return ins;
+ }
+ }
+ }
+ return 0;
+}
+
+
+docstring InsetText::getCaptionText(OutputParams const & runparams) const
+{
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == 0)
+ return docstring();
+
+ odocstringstream ods;
+ ins->getCaptionAsPlaintext(ods, runparams);
+ return ods.str();
+}
+
+
+docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
+{
+ InsetCaption const * ins = getCaptionInset();
+ if (ins == 0)
+ return docstring();
+
+ odocstringstream ods;
+ docstring def = ins->getCaptionAsHTML(ods, runparams);
+ if (!def.empty())
+ ods << def << '\n';
+ return ods.str();
+}
+
+
} // namespace lyx