2000-06-28 13:35:52 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
|
|
|
|
* Copyright 1998 The LyX Team.
|
|
|
|
|
*
|
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "insetminipage.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
#include "BufferView.h"
|
2001-03-16 15:15:32 +00:00
|
|
|
|
#include "LyXView.h"
|
|
|
|
|
#include "frontends/Dialogs.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "lyxtext.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "support/LOstream.h"
|
2001-03-16 15:15:32 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "debug.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
|
#include "lyxlex.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
|
|
InsetMinipage::InsetMinipage()
|
2001-03-14 14:53:55 +00:00
|
|
|
|
: InsetCollapsable(), pos_(center),
|
|
|
|
|
inner_pos_(inner_center)
|
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
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning Remove this color definitions before 1.2.0 final!
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
2001-07-24 10:13:19 +00:00
|
|
|
|
// just for experimentation :)
|
2001-08-06 14:55:02 +00:00
|
|
|
|
setBackgroundColor(LColor::green);
|
|
|
|
|
inset.setFrameColor(0, LColor::blue);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
setInsetName("Minipage");
|
2001-03-29 15:00:20 +00:00
|
|
|
|
width_ = "100%"; // set default to 100% of column_width
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
|
InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id)
|
|
|
|
|
: InsetCollapsable(in, same_id),
|
|
|
|
|
pos_(in.pos_), inner_pos_(in.inner_pos_),
|
|
|
|
|
height_(in.height_), width_(in.width_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 15:15:32 +00:00
|
|
|
|
InsetMinipage::~InsetMinipage()
|
|
|
|
|
{
|
|
|
|
|
hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetMinipage::write(Buffer const * buf, ostream & os) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2001-03-20 01:22:46 +00:00
|
|
|
|
os << getInsetName() << "\n"
|
|
|
|
|
<< "position " << pos_ << "\n"
|
|
|
|
|
<< "inner_position " << inner_pos_ << "\n"
|
2001-03-22 15:45:15 +00:00
|
|
|
|
<< "height \"" << height_ << "\"\n"
|
2001-03-29 15:00:20 +00:00
|
|
|
|
<< "width \"" << width_ << "\"\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::write(buf, os);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetMinipage::read(Buffer const * buf, 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();
|
2001-08-06 19:13:25 +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();
|
2001-08-06 19:13:25 +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();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
height_ = 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();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
width_ = 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
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
2001-03-20 01:22:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-22 19:36:21 +00:00
|
|
|
|
int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
|
if (collapsed_)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return ascent_collapsed();
|
2001-03-22 19:36:21 +00:00
|
|
|
|
else {
|
|
|
|
|
// Take placement into account.
|
|
|
|
|
int i = 0;
|
|
|
|
|
switch (pos_) {
|
|
|
|
|
case top:
|
|
|
|
|
i = InsetCollapsable::ascent(bv, font);
|
|
|
|
|
break;
|
|
|
|
|
case center:
|
|
|
|
|
i = (InsetCollapsable::ascent(bv, font)
|
|
|
|
|
+ InsetCollapsable::descent(bv, font)) / 2;
|
|
|
|
|
break;
|
|
|
|
|
case bottom:
|
|
|
|
|
i = InsetCollapsable::descent(bv, font);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
2001-07-12 14:35:38 +00:00
|
|
|
|
if (collapsed_)
|
2001-07-24 22:08:49 +00:00
|
|
|
|
return descent_collapsed();
|
2001-03-22 19:36:21 +00:00
|
|
|
|
else {
|
|
|
|
|
// Take placement into account.
|
|
|
|
|
int i = 0;
|
|
|
|
|
switch (pos_) {
|
|
|
|
|
case top:
|
|
|
|
|
i = InsetCollapsable::descent(bv, font);
|
|
|
|
|
break;
|
|
|
|
|
case center:
|
|
|
|
|
i = (InsetCollapsable::ascent(bv, font)
|
|
|
|
|
+ InsetCollapsable::descent(bv, font)) / 2;
|
|
|
|
|
break;
|
|
|
|
|
case bottom:
|
|
|
|
|
i = InsetCollapsable::ascent(bv, font);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetMinipage::latex(Buffer const * buf,
|
2000-06-28 13:35:52 +00:00
|
|
|
|
ostream & os, bool fragile, bool fp) const
|
|
|
|
|
{
|
2001-03-20 01:22:46 +00:00
|
|
|
|
string s_pos;
|
|
|
|
|
switch (pos_) {
|
|
|
|
|
case top:
|
|
|
|
|
s_pos += "t";
|
|
|
|
|
break;
|
|
|
|
|
case center:
|
|
|
|
|
s_pos += "c";
|
|
|
|
|
break;
|
|
|
|
|
case bottom:
|
|
|
|
|
s_pos += "b";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-03-29 15:00:20 +00:00
|
|
|
|
os << "\\begin{minipage}[" << s_pos << "]{"
|
|
|
|
|
<< LyXLength(width_).asLatexString() << "}%\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int i = inset.latex(buf, os, fragile, fp);
|
2001-03-29 15:00:20 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
os << "\\end{minipage}%\n";
|
|
|
|
|
return i + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
bool InsetMinipage::insetAllowed(Inset::Code code) const
|
2001-07-12 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
if ((code == Inset::FLOAT_CODE) || (code == Inset::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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMinipage::Position InsetMinipage::pos() const
|
|
|
|
|
{
|
|
|
|
|
return pos_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMinipage::pos(InsetMinipage::Position p)
|
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (pos_ != p) {
|
|
|
|
|
pos_ = p;
|
|
|
|
|
need_update = FULL;
|
|
|
|
|
}
|
2001-03-14 14:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMinipage::InnerPosition InsetMinipage::innerPos() const
|
|
|
|
|
{
|
|
|
|
|
return inner_pos_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
|
|
|
|
|
{
|
|
|
|
|
inner_pos_ = ip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-22 15:45:15 +00:00
|
|
|
|
string const & InsetMinipage::height() const
|
2001-03-14 14:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
return height_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-22 15:45:15 +00:00
|
|
|
|
void InsetMinipage::height(string const & ll)
|
2001-03-14 14:53:55 +00:00
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (height_ != ll) {
|
|
|
|
|
height_ = ll;
|
|
|
|
|
need_update = FULL;
|
|
|
|
|
}
|
2001-03-14 14:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 15:15:32 +00:00
|
|
|
|
string const & InsetMinipage::width() const
|
2001-03-14 14:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
return width_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 15:15:32 +00:00
|
|
|
|
void InsetMinipage::width(string const & ll)
|
2001-03-14 14:53:55 +00:00
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (ll != width_) {
|
|
|
|
|
width_ = ll;
|
|
|
|
|
need_update = FULL;
|
|
|
|
|
}
|
2001-03-14 14:53:55 +00:00
|
|
|
|
}
|
2001-03-16 15:15:32 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool InsetMinipage::showInsetDialog(BufferView * bv) const
|
2001-03-26 14:47:34 +00:00
|
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if (!inset.showInsetDialog(bv))
|
2001-07-20 14:18:48 +00:00
|
|
|
|
bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
|
2001-05-28 15:11:24 +00:00
|
|
|
|
return true;
|
2001-03-26 14:47:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
|
int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
|
2001-05-28 15:11:24 +00:00
|
|
|
|
const
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
2001-08-02 14:55:06 +00:00
|
|
|
|
if (!width_.empty()) {
|
|
|
|
|
int ww1 = VSpace(width_).inPixels(bv);
|
|
|
|
|
int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
|
2001-08-10 14:00:48 +00:00
|
|
|
|
if (ww2 > 0 && ww2 < ww1) {
|
2001-08-02 14:55:06 +00:00
|
|
|
|
return ww2;
|
2001-08-10 14:00:48 +00:00
|
|
|
|
}
|
2001-08-02 14:55:06 +00:00
|
|
|
|
return ww1;
|
|
|
|
|
}
|
2001-05-28 15:11:24 +00:00
|
|
|
|
// this should not happen!
|
|
|
|
|
return InsetCollapsable::getMaxWidth(bv, inset);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|