#include "BufferView.h"
#include "Cursor.h"
#include "Dimension.h"
-#include "DispatchResult.h"
#include "FloatList.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetLayout.h"
-#include "InsetList.h"
-#include "Language.h"
-#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "MetricsInfo.h"
-#include "output_xhtml.h"
-#include "paragraph_funcs.h"
-#include "ParagraphParameters.h"
-#include "sgml.h"
-#include "TextClass.h"
+#include "OutputParams.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
namespace lyx {
+InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
+ : InsetText(buf, ltype), status_(Open),
+ openinlined_(false), mouse_hover_(false)
+{
+ setAutoBreakRows(true);
+ setDrawFrame(true);
+ setFrameColor(Color_collapsableframe);
+}
+
+
+InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
+ : InsetText(rhs),
+ status_(rhs.status_),
+ labelstring_(rhs.labelstring_),
+ button_dim(rhs.button_dim),
+ openinlined_(rhs.openinlined_),
+ auto_open_(rhs.auto_open_),
+ // the sole purpose of this copy constructor
+ mouse_hover_(false)
+{
+}
+
+
InsetCollapsable::CollapseStatus InsetCollapsable::status(BufferView const & bv) const
{
if (decoration() == InsetLayout::CONGLOMERATE)
}
-InsetCollapsable::InsetCollapsable(Buffer const & buf, InsetText::UsePlain ltype)
- : InsetText(buf, ltype), status_(Inset::Open),
- openinlined_(false), mouse_hover_(false)
-{
- setAutoBreakRows(true);
- setDrawFrame(true);
- setFrameColor(Color_collapsableframe);
-}
-
-
-InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
- : InsetText(rhs),
- status_(rhs.status_),
- labelstring_(rhs.labelstring_),
- button_dim(rhs.button_dim),
- openinlined_(rhs.openinlined_),
- auto_open_(rhs.auto_open_),
- // the sole purpose of this copy constructor
- mouse_hover_(false)
-{
-}
-
-
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
Dimension dim = dimensionCollapsed(bv);
break;
}
os << "\n";
- text().write(buffer(), os);
+ text().write(os);
}
// Draw button first -- top, left or only
Dimension dimc = dimensionCollapsed(bv);
- if (geometry(*pi.base.bv) == TopButton ||
- geometry(*pi.base.bv) == LeftButton ||
- geometry(*pi.base.bv) == ButtonOnly) {
+ if (geometry(bv) == TopButton ||
+ geometry(bv) == LeftButton ||
+ geometry(bv) == ButtonOnly) {
button_dim.x1 = x + 0;
button_dim.x2 = x + dimc.width();
button_dim.y1 = y - dimc.asc;
{
if (geometry(bv) == ButtonOnly)
status_ = Open;
- LASSERT(geometry(bv) != ButtonOnly, /**/);
InsetText::cursorPos(bv, sl, boundary, x, y);
Dimension const textdim = InsetText::dimension(bv);
}
-bool InsetCollapsable::descendable() const
+bool InsetCollapsable::descendable(BufferView const & bv) const
{
- return geometry() != ButtonOnly;
+ return geometry(bv) != ButtonOnly;
}
}
-docstring const InsetCollapsable::buttonLabel(BufferView const &) const
+docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const
{
- return labelstring_.empty() ? getLayout().labelstring() : labelstring_;
+ docstring const label = labelstring_.empty() ?
+ translateIfPossible(getLayout().labelstring()) : labelstring_;
+ InsetLayout const & il = getLayout();
+ if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
+ return label;
+ return getNewLabel(label);
}
}
-int InsetCollapsable::latex(odocstream & os,
- OutputParams const & runparams) const
-{
- // This implements the standard way of handling the LaTeX output of
- // a collapsable inset, either a command or an environment. Standard
- // collapsable insets should not redefine this, non-standard ones may
- // call this.
- InsetLayout const & il = getLayout();
- if (!il.latexname().empty()) {
- if (il.latextype() == InsetLayout::COMMAND) {
- // FIXME UNICODE
- if (runparams.moving_arg)
- os << "\\protect";
- os << '\\' << from_utf8(il.latexname());
- 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.latexparam().empty())
- os << from_utf8(il.latexparam());
- }
- }
- OutputParams rp = runparams;
- if (il.isPassThru())
- rp.verbatim = true;
- if (il.isNeedProtect())
- rp.moving_arg = true;
- int i = InsetText::latex(os, rp);
- if (!il.latexname().empty()) {
- if (il.latextype() == InsetLayout::COMMAND) {
- os << "}";
- } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
- os << "\n\\end{" << from_utf8(il.latexname()) << "}\n";
- i += 4;
- }
- }
- return i;
-}
-
-
-// FIXME It seems as if it ought to be possible to do this more simply,
-// maybe by calling InsetText::docbook() in the middle there.
-int InsetCollapsable::docbook(odocstream & os, OutputParams const & runparams) const
-{
- ParagraphList::const_iterator const beg = paragraphs().begin();
- ParagraphList::const_iterator par = paragraphs().begin();
- ParagraphList::const_iterator const end = paragraphs().end();
-
- if (!undefined())
- sgml::openTag(os, getLayout().latexname(),
- par->getID(buffer(), runparams) + getLayout().latexparam());
-
- for (; par != end; ++par) {
- par->simpleDocBookOnePar(buffer(), os, runparams,
- outerFont(distance(beg, par),
- paragraphs()));
- }
-
- if (!undefined())
- sgml::closeTag(os, getLayout().latexname());
-
- return 0;
-}
-
-
-docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparams) const
-{
- InsetLayout const & il = getLayout();
- if (undefined())
- return InsetText::xhtml(os, runparams);
-
- bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
- if (!il.counter().empty()) {
- BufferParams const & bp = buffer().masterBuffer()->params();
- Counters & cntrs = bp.documentClass().counters();
- cntrs.step(il.counter());
- // FIXME: translate to paragraph language
- if (!il.htmllabel().empty())
- os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
- }
- bool innertag_opened = false;
- if (!il.htmlinnertag().empty())
- innertag_opened = html::openTag(os, il.htmlinnertag(), il.htmlinnerattr());
- docstring deferred = InsetText::xhtml(os, runparams);
- if (innertag_opened)
- html::closeTag(os, il.htmlinnertag());
- if (opened)
- html::closeTag(os, il.htmltag());
- return deferred;
-}
-
-
-void InsetCollapsable::validate(LaTeXFeatures & features) const
-{
- features.useInsetLayout(getLayout());
- InsetText::validate(features);
-}
-
-
-bool InsetCollapsable::undefined() const
-{
- docstring const & n = getLayout().name();
- return n.empty() || n == DocumentClass::plainInsetLayout().name();
-}
-
-
docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
int y) const
{
return InsetText::contextMenu(bv, x, y);
}
-void InsetCollapsable::tocString(odocstream & os) const
-{
- if (!getLayout().isInToc())
- return;
- os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
-}
-
-
} // namespace lyx