lyx_mirror/src/insets/insetminipage.C
Jürgen Vigna 26b1fa7be8 Various update/redraw fixes. Cleaned up InsetERT and added a dialog for
changing between statuses. Save the statuses to file.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2425 a592a061-630c-0410-9148-cb99ea01b6c8
2001-08-06 14:55:02 +00:00

351 lines
7.4 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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"
#include "LyXView.h"
#include "frontends/Dialogs.h"
#include "lyxtext.h"
#include "insets/insettext.h"
#include "support/LOstream.h"
#include "support/lstrings.h"
#include "debug.h"
#include "gettext.h"
#include "lyxlex.h"
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] = 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()
: InsetCollapsable(), pos_(center),
inner_pos_(inner_center)
{
setLabel(_("minipage"));
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
font.decSize();
font.setColor(LColor::collapsable);
setLabelFont(font);
#if 0
setAutoCollapse(false);
#endif
#ifdef WITH_WARNINGS
#warning Remove this color definitions before 1.2.0 final!
#endif
// just for experimentation :)
setBackgroundColor(LColor::green);
inset.setFrameColor(0, LColor::blue);
setInsetName("Minipage");
width_ = "100%"; // set default to 100% of column_width
}
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);
}
InsetMinipage::~InsetMinipage()
{
hideDialog();
}
void InsetMinipage::write(Buffer const * buf, ostream & os) const
{
os << getInsetName() << "\n"
<< "position " << pos_ << "\n"
<< "inner_position " << inner_pos_ << "\n"
<< "height \"" << height_ << "\"\n"
<< "width \"" << width_ << "\"\n";
InsetCollapsable::write(buf, os);
}
void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
{
if (lex.IsOK()) {
lex.next();
string const token = lex.GetString();
if (token == "position") {
lex.next();
pos_ = static_cast<Position>(lex.GetInteger());
} else {
lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
}
if (lex.IsOK()) {
lex.next();
string const token = lex.GetString();
if (token == "inner_position") {
lex.next();
inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
} else {
lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
}
if (lex.IsOK()) {
lex.next();
string const token = lex.GetString();
if (token == "height") {
lex.next();
height_ = lex.GetString();
} else {
lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
}
if (lex.IsOK()) {
lex.next();
string const token = lex.GetString();
if (token == "width") {
lex.next();
width_ = lex.GetString();
} else {
lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
}
InsetCollapsable::read(buf, lex);
}
int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
{
if (collapsed_)
return ascent_collapsed();
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();
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;
}
}
string const InsetMinipage::editMessage() const
{
return _("Opened Minipage Inset");
}
int InsetMinipage::latex(Buffer const * buf,
ostream & os, bool fragile, bool fp) const
{
string s_pos;
switch (pos_) {
case top:
s_pos += "t";
break;
case center:
s_pos += "c";
break;
case bottom:
s_pos += "b";
break;
}
os << "\\begin{minipage}[" << s_pos << "]{"
<< LyXLength(width_).asLatexString() << "}%\n";
int i = inset.latex(buf, os, fragile, fp);
os << "\\end{minipage}%\n";
return i + 2;
}
bool InsetMinipage::insetAllowed(Inset::Code code) const
{
if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
return false;
return InsetCollapsable::insetAllowed(code);
}
InsetMinipage::Position InsetMinipage::pos() const
{
return pos_;
}
void InsetMinipage::pos(InsetMinipage::Position p)
{
if (pos_ != p) {
pos_ = p;
need_update = FULL;
}
}
InsetMinipage::InnerPosition InsetMinipage::innerPos() const
{
return inner_pos_;
}
void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
{
inner_pos_ = ip;
}
string const & InsetMinipage::height() const
{
return height_;
}
void InsetMinipage::height(string const & ll)
{
if (height_ != ll) {
height_ = ll;
need_update = FULL;
}
}
string const & InsetMinipage::width() const
{
return width_;
}
void InsetMinipage::width(string const & ll)
{
if (ll != width_) {
width_ = ll;
need_update = FULL;
}
}
bool InsetMinipage::showInsetDialog(BufferView * bv) const
{
if (!inset.showInsetDialog(bv))
bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
return true;
}
void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
int button)
{
if (button == 3) {
showInsetDialog(bv);
return;
}
InsetCollapsable::insetButtonRelease(bv, x, y, button);
}
int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
const
{
if (!width_.empty()) {
int ww1 = VSpace(width_).inPixels(bv);
int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
if (ww2 > 0 && ww2 < ww1)
return ww2;
return ww1;
}
// this should not happen!
return InsetCollapsable::getMaxWidth(bv, inset);
}