* \author Jürgen Vigna
* \author Lars Gullik Bjønnes
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "insetcollapsable.h"
-#include "insettext.h"
+#include "buffer.h"
#include "BufferView.h"
#include "debug.h"
-#include "dimension.h"
-#include "gettext.h"
-#include "lyxfont.h"
+#include "LColor.h"
#include "lyxlex.h"
-#include "lyxtext.h"
-#include "WordLangTuple.h"
#include "funcrequest.h"
-#include "buffer.h"
#include "metricsinfo.h"
+#include "paragraph.h"
+#include "WordLangTuple.h"
#include "frontends/font_metrics.h"
#include "frontends/Painter.h"
#include "frontends/LyXView.h"
-#include "support/LAssert.h"
-#include "support/LOstream.h"
-using namespace lyx::support;
-using namespace lyx::graphics;
+using lyx::graphics::PreviewLoader;
-using std::vector;
-using std::ostream;
using std::endl;
+using std::string;
using std::max;
+using std::ostream;
InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
- : UpdatableInset(), collapsed_(collapsed), inset(bp),
+ : UpdatableInset(), inset(bp), collapsed_(collapsed),
button_dim(0, 0, 0, 0), label("Label"),
#if 0
autocollapse(false),
#endif
- oldWidth(0), in_update(false), first_after_edit(false)
+ in_update(false), first_after_edit(false)
{
inset.setOwner(this);
inset.setAutoBreakRows(true);
- inset.setDrawFrame(0, InsetText::ALWAYS);
- inset.setFrameColor(0, LColor::collapsableframe);
+ inset.setDrawFrame(InsetText::ALWAYS);
+ inset.setFrameColor(LColor::collapsableframe);
setInsetName("Collapsable");
}
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
- : UpdatableInset(in), collapsed_(in.collapsed_),
- framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
- button_dim(0, 0, 0, 0), label(in.label),
+ : UpdatableInset(in), inset(in.inset), collapsed_(in.collapsed_),
+ labelfont_(in.labelfont_), button_dim(0, 0, 0, 0), label(in.label),
#if 0
autocollapse(in.autocollapse),
#endif
- oldWidth(0), in_update(false), first_after_edit(false)
+ in_update(false), first_after_edit(false)
{
- inset.init(&(in.inset));
inset.setOwner(this);
}
}
-void InsetCollapsable::write(Buffer const * buf, ostream & os) const
+void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{
os << "collapsed " << (collapsed_ ? "true" : "false") << "\n";
inset.writeParagraphData(buf, os);
}
-void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
+void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
{
if (lex.isOK()) {
lex.next();
void InsetCollapsable::dimension_collapsed(Dimension & dim) const
{
- font_metrics::buttonText(label, labelfont, dim.wid, dim.asc, dim.des);
+ font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
}
int InsetCollapsable::height_collapsed() const
{
Dimension dim;
- font_metrics::buttonText(label, labelfont, dim.wid, dim.asc, dim.des);
+ font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
return dim.asc + dim.des;
}
void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
{
- pi.pain.buttonText(x, y, label, labelfont);
+ pi.pain.buttonText(x, y, label, labelfont_);
}
void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
{
- Assert(pi.base.bv);
- cache(pi.base.bv);
-
Dimension dim_collapsed;
dimension_collapsed(dim_collapsed);
if (collapsed_ && cmd.button() != mouse_button::button3) {
collapsed_ = false;
- inset.setUpdateStatus(InsetText::FULL);
bv->updateInset(this);
bv->buffer()->markDirty();
return;
}
- if (cmd.button() != mouse_button::button3 && hitButton(cmd))
- {
+ if (cmd.button() != mouse_button::button3 && hitButton(cmd)) {
if (collapsed_) {
collapsed_ = false;
- inset.setUpdateStatus(InsetText::FULL);
- bv->updateInset(this);
- bv->buffer()->markDirty();
} else {
collapsed_ = true;
bv->unlockInset(this);
- bv->updateInset(this);
- bv->buffer()->markDirty();
}
- } else if (!collapsed_ && (cmd.y > button_dim.y2)) {
- ret = (inset.localDispatch(adjustCommand(cmd)) == DISPATCHED);
+ bv->updateInset(this);
+ bv->buffer()->markDirty();
+ } else if (!collapsed_ && cmd.y > button_dim.y2) {
+ ret = inset.localDispatch(adjustCommand(cmd)) == DISPATCHED;
}
if (cmd.button() == mouse_button::button3 && !ret)
showInsetDialog(bv);
}
-int InsetCollapsable::latex(Buffer const * buf, ostream & os,
+int InsetCollapsable::latex(Buffer const & buf, ostream & os,
LatexRunParams const & runparams) const
{
return inset.latex(buf, os, runparams);
}
-int InsetCollapsable::ascii(Buffer const * buf, ostream & os, int ll) const
+int InsetCollapsable::ascii(Buffer const & buf, ostream & os, int ll) const
{
return inset.ascii(buf, os, ll);
}
-int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const
+int InsetCollapsable::linuxdoc(Buffer const & buf, ostream & os) const
{
return inset.linuxdoc(buf, os);
}
-int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) const
+int InsetCollapsable::docbook(Buffer const & buf, ostream & os, bool mixcont) const
{
return inset.docbook(buf, os, mixcont);
}
bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
{
- return button_dim.contained(cmd.x, cmd.y);
+ return button_dim.contains(cmd.x, cmd.y);
}
-InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
+dispatch_result InsetCollapsable::localDispatch(FuncRequest const & cmd)
{
//lyxerr << "InsetCollapsable::localDispatch: "
// << cmd.action << " '" << cmd.argument << "'\n";
lyxerr << "branch collapsed_" << endl;
collapsed_ = false;
if (bv->lockInset(this)) {
- inset.setUpdateStatus(InsetText::FULL);
bv->updateInset(this);
bv->buffer()->markDirty();
inset.localDispatch(cmd);
bv->buffer()->markDirty();
inset.localDispatch(cmd);
} else {
- FuncRequest cmd1 = cmd;
if (!bv->lockInset(this))
return DISPATCHED;
if (cmd.y <= button_dim.y2) {
+ FuncRequest cmd1 = cmd;
cmd1.y = 0;
- } else {
- cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent());
- }
- inset.localDispatch(cmd);
+ inset.localDispatch(cmd1);
+ } else
+ inset.localDispatch(adjustCommand(cmd));
}
return DISPATCHED;
}
return DISPATCHED;
default:
- UpdatableInset::RESULT result = inset.localDispatch(cmd);
+ dispatch_result result = inset.localDispatch(cmd);
if (result >= FINISHED)
bv->unlockInset(this);
first_after_edit = false;
}
-bool InsetCollapsable::updateInsetInInset(BufferView * bv, InsetOld *in)
-{
- if (in == this)
- return true;
- return inset.updateInsetInInset(bv, in);
-}
-
-
int InsetCollapsable::insetInInsetY() const
{
return inset.insetInInsetY() - (top_baseline - inset.y());
}
-void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const
+void InsetCollapsable::getLabelList(Buffer const & buffer,
+ std::vector<string> & list) const
{
- inset.resizeLyXText(bv, force);
- oldWidth = width();
-}
-
-
-void InsetCollapsable::getLabelList(std::vector<string> & list) const
-{
- inset.getLabelList(list);
+ inset.getLabelList(buffer, list);
}
void InsetCollapsable::open(BufferView * bv)
{
- if (!collapsed_) return;
+ if (!collapsed_)
+ return;
collapsed_ = false;
bv->updateInset(this);
return;
collapsed_ = true;
- bv->updateInset(const_cast<InsetCollapsable *>(this));
+ bv->updateInset(this);
}
}
+void InsetCollapsable::setCollapsed(bool c) const
+{
+ collapsed_ = c;
+}
+
+
void InsetCollapsable::markErased()
{
inset.markErased();
{
inset.addPreview(loader);
}
-
-
-void InsetCollapsable::cache(BufferView * bv) const
-{
- view_ = bv->owner()->view();
-}
-
-
-BufferView * InsetCollapsable::view() const
-{
- return view_.lock().get();
-}