2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetminipage.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetminipage.h"
|
2003-03-07 14:08:10 +00:00
|
|
|
|
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-03-07 14:08:10 +00:00
|
|
|
|
#include "funcrequest.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2003-03-07 14:08:10 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-07-18 07:47:07 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-03-07 14:08:10 +00:00
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
using std::endl;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Some information about Minipages in LaTeX:
|
|
|
|
|
// A minipage is a complete miniversion of a page and can contain
|
|
|
|
|
// its own footnotes, paragraphs, and array, tabular, and multicols
|
|
|
|
|
// environments. However it cannot contain floats or \marginpar's,
|
|
|
|
|
// but it can appear inside floats.
|
|
|
|
|
//
|
|
|
|
|
// The minipage environment is defined like this:
|
|
|
|
|
//
|
|
|
|
|
// \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
|
|
|
|
|
//
|
|
|
|
|
// Where:
|
|
|
|
|
// pos [opt] = is the vertical placement of the box with respect
|
|
|
|
|
// to the text baseline, [c], [t] and [b].
|
|
|
|
|
// height [opt] = the height of the box
|
|
|
|
|
// inner-pos [opt] =<3D>the position of the text within the box.
|
|
|
|
|
// It can be t, c, b or s, if unspecified the value
|
|
|
|
|
// of pos is used.
|
|
|
|
|
// width = the width of the box
|
|
|
|
|
//
|
|
|
|
|
// In LyX we should try to support all these parameters, settable in a
|
|
|
|
|
// pop-up dialog.
|
|
|
|
|
// In this pop-up diallog it should also be possible to set all margin
|
|
|
|
|
// values that is usable in the minipage.
|
|
|
|
|
// With regard to different formats (like DocBook) I guess a minipage
|
|
|
|
|
// can be used there also. Perhaps not in the latex way, but we do not
|
|
|
|
|
// have to output "" for minipages.
|
|
|
|
|
// (Lgb)
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetMinipage::InsetMinipage(BufferParams const & bp)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: InsetCollapsable(bp)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
|
|
|
|
setLabel(_("minipage"));
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
2001-06-05 17:05:51 +00:00
|
|
|
|
font.setColor(LColor::collapsable);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
setLabelFont(font);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
2000-06-28 13:35:52 +00:00
|
|
|
|
setAutoCollapse(false);
|
2001-08-06 14:55:02 +00:00
|
|
|
|
#endif
|
2003-08-11 09:09:01 +00:00
|
|
|
|
inset.setFrameColor(LColor::blue);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
setInsetName("Minipage");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetMinipage::InsetMinipage(InsetMinipage const & in)
|
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMinipage::clone() const
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMinipage(*this));
|
2001-07-24 15:07:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 15:15:32 +00:00
|
|
|
|
InsetMinipage::~InsetMinipage()
|
|
|
|
|
{
|
2003-08-05 08:07:07 +00:00
|
|
|
|
InsetMinipageMailer(*this).hideDialog();
|
2001-03-16 15:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2003-10-17 18:01:15 +00:00
|
|
|
|
InsetMinipage::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
|
idx_type & idx, pos_type & pos)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetMinipage::Params params;
|
|
|
|
|
InsetMinipageMailer::string2params(cmd.argument, params);
|
|
|
|
|
|
|
|
|
|
params_.pos = params.pos;
|
|
|
|
|
params_.width = params.width;
|
|
|
|
|
|
2003-03-22 17:26:03 +00:00
|
|
|
|
/* FIXME: I refuse to believe we have to live
|
|
|
|
|
* with ugliness like this ... */
|
2003-06-27 09:44:26 +00:00
|
|
|
|
inset.getLyXText(cmd.view())->fullRebreak();
|
2003-08-27 13:51:18 +00:00
|
|
|
|
cmd.view()->updateInset(this);
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
}
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2003-05-16 14:48:33 +00:00
|
|
|
|
InsetMinipageMailer(*this).updateDialog(cmd.view());
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
void InsetMinipage::Params::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "Minipage" << '\n'
|
|
|
|
|
<< "position " << pos << '\n'
|
|
|
|
|
<< "inner_position " << inner_pos << '\n'
|
|
|
|
|
<< "height \"" << height.asString() << "\"\n"
|
|
|
|
|
<< "width \"" << width.asString() << "\"\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMinipage::Params::read(LyXLex & lex)
|
2001-03-20 01:22:46 +00:00
|
|
|
|
{
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-05-28 15:11:24 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (token == "position") {
|
|
|
|
|
lex.next();
|
2003-03-07 14:08:10 +00:00
|
|
|
|
pos = static_cast<Position>(lex.getInteger());
|
2001-05-28 15:11:24 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
|
|
|
|
|
<< endl;
|
2001-07-25 22:05:53 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-07-25 22:05:53 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (token == "inner_position") {
|
|
|
|
|
lex.next();
|
2003-03-07 14:08:10 +00:00
|
|
|
|
inner_pos = static_cast<InnerPosition>(lex.getInteger());
|
2001-05-28 15:11:24 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
|
|
|
|
|
<< endl;
|
2001-07-25 22:05:53 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-07-25 22:05:53 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (token == "height") {
|
|
|
|
|
lex.next();
|
2003-03-07 14:08:10 +00:00
|
|
|
|
height = LyXLength(lex.getString());
|
2001-05-28 15:11:24 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
|
|
|
|
|
<< endl;
|
2001-07-25 22:05:53 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2001-07-25 22:05:53 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (token == "width") {
|
|
|
|
|
lex.next();
|
2003-03-07 14:08:10 +00:00
|
|
|
|
width = LyXLength(lex.getString());
|
2001-05-28 15:11:24 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
|
|
|
|
|
<< endl;
|
2001-07-25 22:05:53 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2003-03-07 14:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetMinipage::write(Buffer const & buf, ostream & os) const
|
2003-03-07 14:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetMinipage::read(Buffer const & buf, LyXLex & lex)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
params_.read(lex);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
2001-03-20 01:22:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-03-22 19:36:21 +00:00
|
|
|
|
{
|
2003-09-16 15:39:33 +00:00
|
|
|
|
if (isOpen()) {
|
2003-05-19 17:03:12 +00:00
|
|
|
|
Dimension d;
|
2003-07-18 07:47:07 +00:00
|
|
|
|
MetricsInfo m = mi;
|
|
|
|
|
m.base.textwidth = params_.width.inPixels(mi.base.textwidth);
|
|
|
|
|
InsetCollapsable::metrics(m, d);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
switch (params_.pos) {
|
2001-03-22 19:36:21 +00:00
|
|
|
|
case top:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.asc = d.asc;
|
|
|
|
|
dim.des = d.des;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
break;
|
|
|
|
|
case center:
|
2003-05-28 16:36:55 +00:00
|
|
|
|
dim.asc = d.ascent() + d.descent() / 2;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.des = dim.asc;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
break;
|
|
|
|
|
case bottom:
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim.asc = d.des;
|
|
|
|
|
dim.des = d.asc;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-05-28 16:36:55 +00:00
|
|
|
|
dim.wid = d.wid;
|
2003-09-16 15:39:33 +00:00
|
|
|
|
} else
|
|
|
|
|
dimension_collapsed(dim);
|
|
|
|
|
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
string const InsetMinipage::editMessage() const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
|
|
|
|
return _("Opened Minipage Inset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetMinipage::latex(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2001-03-20 01:22:46 +00:00
|
|
|
|
string s_pos;
|
2003-03-07 14:08:10 +00:00
|
|
|
|
switch (params_.pos) {
|
2001-03-20 01:22:46 +00:00
|
|
|
|
case top:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
s_pos += 't';
|
2001-03-20 01:22:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case center:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
s_pos += 'c';
|
2001-03-20 01:22:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case bottom:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
s_pos += 'b';
|
2001-03-20 01:22:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-03-29 15:00:20 +00:00
|
|
|
|
os << "\\begin{minipage}[" << s_pos << "]{"
|
2003-03-07 14:08:10 +00:00
|
|
|
|
<< params_.width.asLatexString() << "}%\n";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-05-23 08:59:47 +00:00
|
|
|
|
int i = inset.latex(buf, os, runparams);
|
2001-03-29 15:00:20 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
os << "\\end{minipage}%\n";
|
|
|
|
|
return i + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
bool InsetMinipage::insetAllowed(InsetOld::Code code) const
|
2001-07-12 14:35:38 +00:00
|
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (code == InsetOld::FLOAT_CODE || code == InsetOld::MARGIN_CODE)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
return false;
|
2001-07-12 14:35:38 +00:00
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
return InsetCollapsable::insetAllowed(code);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
2001-03-14 14:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetMinipage::showInsetDialog(BufferView * bv) const
|
2001-03-26 14:47:34 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
if (!inset.showInsetDialog(bv)) {
|
|
|
|
|
InsetMinipage * tmp = const_cast<InsetMinipage *>(this);
|
|
|
|
|
InsetMinipageMailer mailer(*tmp);
|
2003-03-10 22:12:07 +00:00
|
|
|
|
mailer.showDialog(bv);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
|
return true;
|
2001-03-26 14:47:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-01-19 17:05:24 +00:00
|
|
|
|
int InsetMinipage::latexTextWidth(BufferView * bv) const
|
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMinipage::Params::Params()
|
|
|
|
|
: pos(center),
|
|
|
|
|
inner_pos(inner_center),
|
|
|
|
|
width(100, LyXLength::PCW)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetMinipageMailer:: name_("minipage");
|
|
|
|
|
|
|
|
|
|
InsetMinipageMailer::InsetMinipageMailer(InsetMinipage & inset)
|
|
|
|
|
: inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetMinipageMailer::inset2string(Buffer const &) const
|
2003-03-07 14:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
return params2string(inset_.params());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMinipageMailer::string2params(string const & in,
|
|
|
|
|
InsetMinipage::Params & params)
|
|
|
|
|
{
|
|
|
|
|
params = InsetMinipage::Params();
|
|
|
|
|
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
LyXLex lex(0, 0);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token != "minipage")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
|
// by Buffer::readInset
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token != "Minipage")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-10 03:11:54 +00:00
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
params.read(lex);
|
|
|
|
|
}
|
2003-03-07 14:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
|
|
|
|
InsetMinipageMailer::params2string(InsetMinipage::Params const & params)
|
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
|
|
|
|
data << name_ << ' ';
|
|
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2002-01-19 17:05:24 +00:00
|
|
|
|
}
|