2003-10-07 07:42:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetbox.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Martin Vermeer
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetbox.h"
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
|
|
|
|
#include "debug.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-10-07 07:42:15 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "metricsinfo.h"
|
|
|
|
|
#include "paragraph.h"
|
|
|
|
|
|
2003-12-10 21:48:40 +00:00
|
|
|
|
#include "support/translator.h"
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ostringstream;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2003-12-10 21:48:40 +00:00
|
|
|
|
typedef Translator<std::string, InsetBox::BoxType> BoxTranslator;
|
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
|
BoxTranslator const init_boxtranslator()
|
|
|
|
|
{
|
2003-10-07 07:42:15 +00:00
|
|
|
|
BoxTranslator translator("Boxed", InsetBox::Boxed);
|
|
|
|
|
translator.addPair("Frameless", InsetBox::Frameless);
|
|
|
|
|
translator.addPair("ovalbox", InsetBox::ovalbox);
|
|
|
|
|
translator.addPair("Ovalbox", InsetBox::Ovalbox);
|
|
|
|
|
translator.addPair("Shadowbox", InsetBox::Shadowbox);
|
|
|
|
|
translator.addPair("Doublebox",InsetBox::Doublebox);
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
|
BoxTranslator const init_boxtranslator_loc()
|
|
|
|
|
{
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
BoxTranslator translator(lyx::to_utf8(_("Boxed")), InsetBox::Boxed);
|
|
|
|
|
translator.addPair(lyx::to_utf8(_("Frameless")), InsetBox::Frameless);
|
|
|
|
|
translator.addPair(lyx::to_utf8(_("ovalbox")), InsetBox::ovalbox);
|
|
|
|
|
translator.addPair(lyx::to_utf8(_("Ovalbox")), InsetBox::Ovalbox);
|
|
|
|
|
translator.addPair(lyx::to_utf8(_("Shadowbox")), InsetBox::Shadowbox);
|
|
|
|
|
translator.addPair(lyx::to_utf8(_("Doublebox")), InsetBox::Doublebox);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
|
BoxTranslator const & boxtranslator()
|
|
|
|
|
{
|
2003-10-07 07:42:15 +00:00
|
|
|
|
static BoxTranslator translator = init_boxtranslator();
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
|
BoxTranslator const & boxtranslator_loc()
|
|
|
|
|
{
|
2003-10-07 07:42:15 +00:00
|
|
|
|
static BoxTranslator translator = init_boxtranslator_loc();
|
|
|
|
|
return translator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBox::init()
|
|
|
|
|
{
|
|
|
|
|
setInsetName("Box");
|
|
|
|
|
setButtonLabel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBox::InsetBox(BufferParams const & bp, string const & label)
|
|
|
|
|
: InsetCollapsable(bp), params_(label)
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBox::InsetBox(InsetBox const & in)
|
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBox::~InsetBox()
|
|
|
|
|
{
|
2003-11-28 17:13:41 +00:00
|
|
|
|
InsetBoxMailer(*this).hideDialog();
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetBox::doClone() const
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
return auto_ptr<InsetBase>(new InsetBox(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBox::editMessage() const
|
|
|
|
|
{
|
2006-09-09 15:27:44 +00:00
|
|
|
|
return lyx::to_utf8(_("Opened Box Inset"));
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBox::write(Buffer const & buf, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBox::read(Buffer const & buf, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
params_.read(lex);
|
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
setButtonLabel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBox::setButtonLabel()
|
|
|
|
|
{
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
|
|
|
|
|
BoxType btype = boxtranslator().find(params_.type);
|
2006-09-09 15:27:44 +00:00
|
|
|
|
|
|
|
|
|
string label;
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
label += lyx::to_utf8(_("Box"));
|
|
|
|
|
label += " (";
|
2003-10-07 07:42:15 +00:00
|
|
|
|
if (btype == Frameless) {
|
|
|
|
|
if (params_.use_parbox)
|
2006-09-09 15:27:44 +00:00
|
|
|
|
label += lyx::to_utf8(_("Parbox"));
|
2003-10-07 07:42:15 +00:00
|
|
|
|
else
|
2006-09-09 15:27:44 +00:00
|
|
|
|
label += lyx::to_utf8(_("Minipage"));
|
2003-10-07 07:42:15 +00:00
|
|
|
|
} else
|
2006-09-09 15:27:44 +00:00
|
|
|
|
label += boxtranslator_loc().find(btype);
|
|
|
|
|
label += ")";
|
|
|
|
|
|
|
|
|
|
setLabel(label);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
font.setColor(LColor::foreground);
|
|
|
|
|
setBackgroundColor(LColor::background);
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
MetricsInfo mi = m;
|
2005-12-03 08:59:45 +00:00
|
|
|
|
if (params_.inner_box || params_.special != "width")
|
|
|
|
|
mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
InsetCollapsable::metrics(mi, dim);
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-12-05 15:03:38 +00:00
|
|
|
|
bool InsetBox::forceDefaultParagraphs(idx_type) const
|
|
|
|
|
{
|
|
|
|
|
return !params_.inner_box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
bool InsetBox::showInsetDialog(BufferView * bv) const
|
|
|
|
|
{
|
|
|
|
|
InsetBoxMailer(const_cast<InsetBox &>(*this)).showDialog(bv);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
lyxerr << "InsetBox::dispatch MODIFY" << endl;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
InsetBoxMailer::string2params(lyx::to_utf8(cmd.argument()), params_);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
setButtonLabel();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetBoxMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetBoxMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-03-30 12:43:32 +00:00
|
|
|
|
case LFUN_PASTE:
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
|
case LFUN_CLIPBOARD_PASTE:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_PRIMARY_SELECTION_PASTE:
|
2006-03-30 12:43:32 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
|
|
|
|
if (!params_.inner_box)
|
|
|
|
|
forceParagraphsToDefault(cur);
|
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
|
bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
return true;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
2005-12-05 15:03:38 +00:00
|
|
|
|
if (params_.inner_box) {
|
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
|
} else {
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-04-22 08:57:22 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
int InsetBox::latex(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
BoxType btype = boxtranslator().find(params_.type);
|
|
|
|
|
|
|
|
|
|
string width_string = params_.width.asLatexString();
|
|
|
|
|
bool stdwidth(false);
|
|
|
|
|
if (params_.inner_box &&
|
|
|
|
|
(width_string.find("1.0\\columnwidth") != string::npos
|
|
|
|
|
|| width_string.find("1.0\\textwidth") != string::npos)) {
|
|
|
|
|
stdwidth = true;
|
|
|
|
|
switch (btype) {
|
|
|
|
|
case Frameless:
|
|
|
|
|
break;
|
|
|
|
|
case Boxed:
|
|
|
|
|
width_string += " - 2\\fboxsep - 2\\fboxrule";
|
|
|
|
|
break;
|
|
|
|
|
case ovalbox:
|
|
|
|
|
width_string += " - 2\\fboxsep - 0.8pt";
|
|
|
|
|
break;
|
|
|
|
|
case Ovalbox:
|
|
|
|
|
width_string += " - 2\\fboxsep - 1.6pt";
|
|
|
|
|
break;
|
|
|
|
|
case Shadowbox:
|
|
|
|
|
// Shadow falls outside right margin... opinions?
|
|
|
|
|
width_string += " - 2\\fboxsep - 2\\fboxrule"/* "-\\shadowsize"*/;
|
|
|
|
|
break;
|
|
|
|
|
case Doublebox:
|
|
|
|
|
width_string += " - 2\\fboxsep - 7.5\\fboxrule - 1.0pt";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-10-13 02:10:45 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
os << "%\n";
|
|
|
|
|
// Adapt to column/text width correctly also if paragraphs indented:
|
|
|
|
|
if (stdwidth)
|
|
|
|
|
os << "\\noindent";
|
2003-10-13 02:10:45 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
switch (btype) {
|
|
|
|
|
case Frameless:
|
|
|
|
|
break;
|
|
|
|
|
case Boxed:
|
|
|
|
|
os << "\\framebox";
|
|
|
|
|
if (!params_.inner_box) {
|
|
|
|
|
os << "{\\makebox";
|
|
|
|
|
// Special widths, see usrguide <20>3.5
|
|
|
|
|
if (params_.special != "none") {
|
|
|
|
|
os << "[" << params_.width.value()
|
|
|
|
|
<< "\\" << params_.special << "]";
|
|
|
|
|
} else
|
|
|
|
|
os << "[" << width_string << "]";
|
|
|
|
|
if (params_.hor_pos != 'c')
|
|
|
|
|
os << "[" << params_.hor_pos << "]";
|
|
|
|
|
}
|
2003-10-13 02:10:45 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
os << "{";
|
|
|
|
|
break;
|
|
|
|
|
case ovalbox:
|
|
|
|
|
os << "\\ovalbox{";
|
|
|
|
|
break;
|
|
|
|
|
case Ovalbox:
|
|
|
|
|
os << "\\Ovalbox{";
|
|
|
|
|
break;
|
|
|
|
|
case Shadowbox:
|
|
|
|
|
os << "\\shadowbox{";
|
|
|
|
|
break;
|
|
|
|
|
case Doublebox:
|
|
|
|
|
os << "\\doublebox{";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params_.inner_box) {
|
|
|
|
|
if (params_.use_parbox)
|
|
|
|
|
os << "\\parbox";
|
|
|
|
|
else
|
|
|
|
|
os << "\\begin{minipage}";
|
|
|
|
|
|
|
|
|
|
os << "[" << params_.pos << "]";
|
|
|
|
|
if (params_.height_special == "none") {
|
|
|
|
|
os << "[" << params_.height.asLatexString() << "]";
|
|
|
|
|
} else {
|
|
|
|
|
// Special heights
|
|
|
|
|
os << "[" << params_.height.value()
|
|
|
|
|
<< "\\" << params_.height_special << "]";
|
|
|
|
|
}
|
|
|
|
|
if (params_.inner_pos != params_.pos)
|
|
|
|
|
os << "[" << params_.inner_pos << "]";
|
|
|
|
|
|
|
|
|
|
os << "{" << width_string << "}";
|
|
|
|
|
|
|
|
|
|
if (params_.use_parbox)
|
|
|
|
|
os << "{";
|
|
|
|
|
os << "%\n";
|
|
|
|
|
i += 1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
i += InsetText::latex(buf, os, runparams);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
if (params_.inner_box) {
|
|
|
|
|
if (params_.use_parbox)
|
|
|
|
|
os << "%\n}";
|
|
|
|
|
else
|
|
|
|
|
os << "%\n\\end{minipage}";
|
|
|
|
|
}
|
2003-10-13 02:10:45 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
switch (btype) {
|
|
|
|
|
case Frameless:
|
|
|
|
|
break;
|
|
|
|
|
case Boxed:
|
|
|
|
|
if (!params_.inner_box)
|
|
|
|
|
os << "}"; // for makebox
|
|
|
|
|
os << "}";
|
|
|
|
|
break;
|
|
|
|
|
case ovalbox:
|
|
|
|
|
case Ovalbox:
|
|
|
|
|
case Doublebox:
|
|
|
|
|
case Shadowbox:
|
|
|
|
|
os << "}";
|
|
|
|
|
break;
|
2003-10-13 02:10:45 +00:00
|
|
|
|
}
|
2003-10-07 07:42:15 +00:00
|
|
|
|
os << "%\n";
|
2003-10-13 02:10:45 +00:00
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
i += 3;
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetBox::docbook(Buffer const & buf, std::ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return InsetText::docbook(buf, os, runparams);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetBox::plaintext(Buffer const & buf, std::ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
BoxType const btype = boxtranslator().find(params_.type);
|
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
switch (btype) {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
case Frameless: break;
|
|
|
|
|
case Boxed: os << "["; break;
|
|
|
|
|
case ovalbox: os << "("; break;
|
|
|
|
|
case Ovalbox: os << "(("; break;
|
|
|
|
|
case Shadowbox: os << "["; break;
|
|
|
|
|
case Doublebox: os << "[["; break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int i = InsetText::plaintext(buf, os, runparams);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
switch (btype) {
|
2003-11-10 09:06:48 +00:00
|
|
|
|
case Frameless: break;
|
|
|
|
|
case Boxed: os << "]"; break;
|
|
|
|
|
case ovalbox: os << ")"; break;
|
|
|
|
|
case Ovalbox: os << "))"; break;
|
|
|
|
|
case Shadowbox: os << "]/"; break;
|
|
|
|
|
case Doublebox: os << "]]"; break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBox::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("calc");
|
|
|
|
|
BoxType btype = boxtranslator().find(params_.type);
|
|
|
|
|
switch (btype) {
|
|
|
|
|
case Frameless:
|
|
|
|
|
case Boxed:
|
|
|
|
|
break;
|
|
|
|
|
case ovalbox:
|
|
|
|
|
case Ovalbox:
|
|
|
|
|
case Shadowbox:
|
|
|
|
|
case Doublebox:
|
|
|
|
|
features.require("fancybox");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
InsetText::validate(features);
|
2003-10-07 07:42:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBoxMailer::InsetBoxMailer(InsetBox & inset)
|
|
|
|
|
: inset_(inset)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
{}
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBoxMailer::name_ = "box";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBoxMailer::inset2string(Buffer const &) const
|
|
|
|
|
{
|
|
|
|
|
return params2string(inset_.params());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBoxMailer::params2string(InsetBoxParams const & params)
|
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
|
|
|
|
data << "box" << ' ';
|
|
|
|
|
params.write(data);
|
|
|
|
|
return data.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBoxMailer::string2params(string const & in,
|
2003-12-10 21:48:40 +00:00
|
|
|
|
InsetBoxParams & params)
|
2003-10-07 07:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
params = InsetBoxParams(string());
|
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
istringstream data(in);
|
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
2003-12-10 21:48:40 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetBoxMailer", in, 1, name_);
|
2003-12-10 21:48:40 +00:00
|
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
|
// by LyXText::readInset
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string id;
|
|
|
|
|
lex >> id;
|
|
|
|
|
if (!lex || id != "Box")
|
|
|
|
|
return print_mailer_error("InsetBoxMailer", in, 2, "Box");
|
2003-10-07 07:42:15 +00:00
|
|
|
|
|
|
|
|
|
params.read(lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBoxParams::InsetBoxParams(string const & label)
|
|
|
|
|
: type(label),
|
|
|
|
|
use_parbox(false),
|
|
|
|
|
inner_box(true),
|
|
|
|
|
width(LyXLength("100col%")),
|
|
|
|
|
special("none"),
|
|
|
|
|
pos('t'),
|
|
|
|
|
hor_pos('c'),
|
|
|
|
|
inner_pos('t'),
|
|
|
|
|
height(LyXLength("1in")),
|
|
|
|
|
height_special("totalheight") // default is 1\\totalheight
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBoxParams::write(ostream & os) const
|
|
|
|
|
{
|
2003-12-10 21:48:40 +00:00
|
|
|
|
os << "Box " << type << "\n";
|
2003-10-07 07:42:15 +00:00
|
|
|
|
os << "position \"" << pos << "\"\n";
|
|
|
|
|
os << "hor_pos \"" << hor_pos << "\"\n";
|
|
|
|
|
os << "has_inner_box " << inner_box << "\n";
|
|
|
|
|
os << "inner_pos \"" << inner_pos << "\"\n";
|
|
|
|
|
os << "use_parbox " << use_parbox << "\n";
|
|
|
|
|
os << "width \"" << width.asString() << "\"\n";
|
|
|
|
|
os << "special \"" << special << "\"\n";
|
|
|
|
|
os << "height \"" << height.asString() << "\"\n";
|
|
|
|
|
os << "height_special \"" << height_special << "\"\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBoxParams::read(LyXLex & lex)
|
|
|
|
|
{
|
2003-12-10 21:48:40 +00:00
|
|
|
|
if (!lex.isOK())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-10-07 07:42:15 +00:00
|
|
|
|
if (lex.isOK()) {
|
2003-12-10 21:48:40 +00:00
|
|
|
|
lex.next();
|
2003-10-07 07:42:15 +00:00
|
|
|
|
type = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
2003-12-10 21:48:40 +00:00
|
|
|
|
string token;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "position") {
|
|
|
|
|
lex.next();
|
|
|
|
|
// The [0] is needed. We need the first and only char in
|
|
|
|
|
// this string -- MV
|
|
|
|
|
pos = lex.getString()[0];
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "hor_pos") {
|
|
|
|
|
lex.next();
|
|
|
|
|
hor_pos = lex.getString()[0];
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "has_inner_box") {
|
|
|
|
|
lex.next();
|
|
|
|
|
inner_box = lex.getInteger();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'has_inner_box'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "inner_pos") {
|
|
|
|
|
lex.next();
|
|
|
|
|
inner_pos = lex.getString()[0];
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'inner_pos'-tag!"
|
|
|
|
|
<< token << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "use_parbox") {
|
|
|
|
|
lex.next();
|
|
|
|
|
use_parbox = lex.getInteger();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "width") {
|
|
|
|
|
lex.next();
|
|
|
|
|
width = LyXLength(lex.getString());
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "special") {
|
|
|
|
|
lex.next();
|
|
|
|
|
special = lex.getString();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "height") {
|
|
|
|
|
lex.next();
|
|
|
|
|
height = LyXLength(lex.getString());
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex.isOK())
|
2003-10-13 02:10:45 +00:00
|
|
|
|
return;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "height_special") {
|
|
|
|
|
lex.next();
|
|
|
|
|
height_special = lex.getString();
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetBox::Read: Missing 'height_special'-tag!" << endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
}
|