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"
|
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();
|
|
|
|
|
font.setColor(LColor::footnote);
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
setAutoCollapse(false);
|
|
|
|
|
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-03-16 15:15:32 +00:00
|
|
|
|
InsetMinipage::~InsetMinipage()
|
|
|
|
|
{
|
|
|
|
|
hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
void InsetMinipage::Write(Buffer const * buf, ostream & os) const
|
|
|
|
|
{
|
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";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
InsetCollapsable::Write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
void InsetMinipage::Read(Buffer const * buf, LyXLex & lex)
|
|
|
|
|
{
|
2001-03-22 15:45:15 +00:00
|
|
|
|
string token;
|
|
|
|
|
|
|
|
|
|
if (lex.IsOK()) {
|
2001-03-20 01:22:46 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
2001-03-22 15:45:15 +00:00
|
|
|
|
if (token == "position") {
|
|
|
|
|
lex.next();
|
|
|
|
|
pos_ = static_cast<Position>(lex.GetInteger());
|
|
|
|
|
token = string();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
if (token.empty()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
if (token == "inner_position") {
|
|
|
|
|
lex.next();
|
|
|
|
|
inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
|
|
|
|
|
token = string();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
if (token.empty()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
if (token == "height") {
|
|
|
|
|
lex.next();
|
|
|
|
|
height_ = lex.GetString();
|
|
|
|
|
token = string();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
if (token.empty()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
if (token == "width") {
|
|
|
|
|
lex.next();
|
|
|
|
|
width_ = lex.GetString();
|
|
|
|
|
token = string();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-17 00:19:49 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2001-03-29 15:00:20 +00:00
|
|
|
|
#warning Remove me before final 1.2.0 (Jug)
|
2001-04-17 00:19:49 +00:00
|
|
|
|
#endif
|
2001-03-29 15:00:20 +00:00
|
|
|
|
// this is only for compatibility to the intermediate format and should
|
|
|
|
|
// vanish till the final 1.2.0!
|
2001-03-22 15:45:15 +00:00
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
if (token.empty()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
if (token == "widthp") {
|
|
|
|
|
lex.next();
|
2001-03-29 15:00:20 +00:00
|
|
|
|
// only do this if the width_-string was not already set!
|
|
|
|
|
if (width_.empty())
|
|
|
|
|
width_ = lex.GetString() + "%";
|
2001-03-22 15:45:15 +00:00
|
|
|
|
token = string();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-29 15:00:20 +00:00
|
|
|
|
if (!token.empty())
|
|
|
|
|
lex.pushToken(token);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
InsetCollapsable::Read(buf, lex);
|
2001-03-20 01:22:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
|
Inset * InsetMinipage::Clone(Buffer const &) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
|
|
|
|
InsetMinipage * result = new InsetMinipage;
|
2001-03-30 14:28:17 +00:00
|
|
|
|
result->inset.init(&inset);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
result->collapsed = collapsed;
|
2001-03-28 09:28:48 +00:00
|
|
|
|
result->pos_ = pos_;
|
|
|
|
|
result->inner_pos_ = inner_pos_;
|
|
|
|
|
result->height_ = height_;
|
|
|
|
|
result->width_ = width_;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-22 19:36:21 +00:00
|
|
|
|
int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
|
|
|
|
if (collapsed)
|
|
|
|
|
return ascent_collapsed(bv->painter(), font);
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
if (collapsed)
|
|
|
|
|
return descent_collapsed(bv->painter(), font);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const InsetMinipage::EditMessage() const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
|
|
|
|
return _("Opened Minipage Inset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMinipage::Latex(Buffer const * buf,
|
|
|
|
|
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-03-30 14:28:17 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
|
bool InsetMinipage::InsertInsetAllowed(Inset * in) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-07-04 11:30:07 +00:00
|
|
|
|
if ((in->LyxCode() == Inset::FLOAT_CODE) ||
|
|
|
|
|
(in->LyxCode() == Inset::MARGIN_CODE)) {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-03-14 14:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMinipage::Position InsetMinipage::pos() const
|
|
|
|
|
{
|
|
|
|
|
return pos_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMinipage::pos(InsetMinipage::Position p)
|
|
|
|
|
{
|
|
|
|
|
pos_ = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
height_ = ll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
width_ = ll;
|
|
|
|
|
}
|
2001-03-16 15:15:32 +00:00
|
|
|
|
|
|
|
|
|
|
2001-03-26 14:47:34 +00:00
|
|
|
|
bool InsetMinipage::ShowInsetDialog(BufferView * bv) const
|
|
|
|
|
{
|
2001-03-30 14:28:17 +00:00
|
|
|
|
if (!inset.ShowInsetDialog(bv))
|
2001-03-26 14:47:34 +00:00
|
|
|
|
bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 15:15:32 +00:00
|
|
|
|
void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
|
|
|
|
|
int button)
|
|
|
|
|
{
|
|
|
|
|
if (button == 3) {
|
2001-03-26 14:47:34 +00:00
|
|
|
|
ShowInsetDialog(bv);
|
2001-03-16 15:15:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
InsetCollapsable::InsetButtonRelease(bv, x, y, button);
|
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
|
2001-03-28 09:28:48 +00:00
|
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
|
int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
|
2001-03-22 15:45:15 +00:00
|
|
|
|
const
|
|
|
|
|
{
|
|
|
|
|
if (!width_.empty())
|
2001-03-29 15:00:20 +00:00
|
|
|
|
return VSpace(width_).inPixels(bv);
|
|
|
|
|
// this should not happen!
|
|
|
|
|
return InsetCollapsable::getMaxWidth(bv, inset);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|