2003-11-12 14:38:26 +00:00
|
|
|
/**
|
2007-09-05 15:29:04 +00:00
|
|
|
* \file InsetFlex.cpp
|
2003-11-12 14:38:26 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Martin Vermeer
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2003-11-12 14:38:26 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
#include "InsetFlex.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2009-10-26 23:49:43 +00:00
|
|
|
#include "Cursor.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "TextClass.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
|
|
|
|
#include "support/gettext.h"
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2008-04-09 09:36:08 +00:00
|
|
|
#include <ostream>
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
|
2008-10-26 02:25:57 +00:00
|
|
|
: InsetCollapsable(buf), name_(layoutName)
|
2012-12-08 08:35:52 +00:00
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2007-09-05 15:29:04 +00:00
|
|
|
InsetFlex::InsetFlex(InsetFlex const & in)
|
2007-11-05 10:14:19 +00:00
|
|
|
: InsetCollapsable(in), name_(in.name_)
|
2007-11-03 00:56:48 +00:00
|
|
|
{}
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
|
|
|
2012-04-22 10:32:41 +00:00
|
|
|
// special code for InsetFlex when there is not the explicit Flex:: prefix
|
2010-10-12 15:37:02 +00:00
|
|
|
InsetLayout const & InsetFlex::getLayout() const
|
|
|
|
{
|
2010-11-26 16:45:58 +00:00
|
|
|
if (!buffer_)
|
|
|
|
return DocumentClass::plainInsetLayout();
|
|
|
|
|
2010-10-12 15:37:02 +00:00
|
|
|
DocumentClass const & dc = buffer().params().documentClass();
|
|
|
|
docstring const dname = from_utf8(name_);
|
|
|
|
if (dc.hasInsetLayout(dname))
|
|
|
|
return dc.insetLayout(dname);
|
|
|
|
return dc.insetLayout(from_utf8("Flex:" + name_));
|
2010-10-12 14:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 19:41:04 +00:00
|
|
|
bool InsetFlex::resetFontEdit() const
|
|
|
|
{
|
|
|
|
if (getLayout().resetsFont())
|
|
|
|
return true;
|
|
|
|
return InsetCollapsable::resetFontEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 14:06:05 +00:00
|
|
|
InsetLayout::InsetDecoration InsetFlex::decoration() const
|
|
|
|
{
|
|
|
|
InsetLayout::InsetDecoration const dec = getLayout().decoration();
|
|
|
|
return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFlex::write(ostream & os) const
|
2003-11-12 14:38:26 +00:00
|
|
|
{
|
2008-02-14 03:42:54 +00:00
|
|
|
os << "Flex " <<
|
2008-02-14 03:49:12 +00:00
|
|
|
(name_.empty() ? "undefined" : name_) << "\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2003-11-12 14:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-26 23:49:43 +00:00
|
|
|
bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-10-26 23:49:43 +00:00
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
InsetLayout::InsetLyXType const type =
|
|
|
|
translateLyXType(to_utf8(cmd.argument()));
|
|
|
|
if (il.lyxtype() == type) {
|
|
|
|
FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
|
|
|
|
return InsetCollapsable::getStatus(cur, temp_cmd, flag);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-10-26 23:49:43 +00:00
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
if (!cmd.argument().empty()) {
|
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
InsetLayout::InsetLyXType const type =
|
|
|
|
translateLyXType(to_utf8(cmd.argument()));
|
|
|
|
|
|
|
|
if (il.lyxtype() == type) {
|
|
|
|
FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
|
|
|
|
InsetCollapsable::doDispatch(cur, temp_cmd);
|
|
|
|
} else
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
default:
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|