support for the LaTeX commands \*phantom, fileformat change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28292 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-01-30 00:56:37 +00:00
parent 1f94bc302a
commit b742ff6406
22 changed files with 722 additions and 48 deletions

View File

@ -1,6 +1,12 @@
LyX file-format changes
-----------------------
2009-01-30 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 348: support for \*phantom.
2009-01-03 Vincent van Ravesteijn <V.F.vanRavesteijn@tudelft.nl>
* Format incremented to 347: support for tabular valign.
2008-11-28 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 346: support for German (Switzerland):
(bug 5450)

View File

@ -996,6 +996,7 @@ src_insets_header_files = Split('''
InsetNomencl.h
InsetNote.h
InsetOptArg.h
InsetPhantom.h
InsetQuotes.h
InsetRef.h
InsetSpace.h
@ -1050,6 +1051,7 @@ src_insets_files = Split('''
InsetNomencl.cpp
InsetNote.cpp
InsetOptArg.cpp
InsetPhantom.cpp
InsetQuotes.cpp
InsetRef.cpp
InsetSpace.cpp

View File

@ -157,6 +157,27 @@ InsetLayout ERT
ForceLTR true
End
InsetLayout Phantom:Phantom
LatexType command
LatexName phantom
Decoration minimalistic
Font
Color phantomtext
EndFont
MultiPar false
End
InsetLayout Phantom:HPhantom
CopyStyle Phantom:Phantom
LatexName hphantom
End
InsetLayout Phantom:VPhantom
CopyStyle Phantom:Phantom
LatexName vphantom
End
InsetLayout Listings
LabelString Listings
LatexType none

View File

@ -48,50 +48,136 @@ def revert_swiss(document):
document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
j = j + 1
def revert_tabularvalign(document):
"Revert the tabular valign option"
i = 0
while True:
i = find_token(document.body, "\\begin_inset Tabular", i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of tabular.")
i = j
continue
k = find_token(document.body, "<features tabularvalignment=", i)
if k == -1:
i = j
continue
# which valignment is specified?
tabularvalignment_re = re.compile(r'<features tabularvalignment="(top|bottom)">')
m = tabularvalignment_re.match(document.body[k])
if not m:
i = j
continue
tabularvalignment = m.group(1)
subst = ['\\end_layout', '\\end_inset']
document.body[j+1:j+1] = subst # just inserts those lines
subst = ['\\begin_inset Box Frameless',
'position "' + tabularvalignment[0] +'"',
'hor_pos "c"',
'has_inner_box 1',
'inner_pos "c"',
'use_parbox 0',
'width "0col%"',
'special "none"',
'height "1in"',
'height_special "totalheight"',
'status open',
'',
'\\begin_layout Plain Layout']
document.body[i:i] = subst # this just inserts the array at i
i += len(subst) + 2 # adjust i to save a few cycles
def revert_tabularvalign(document):
"Revert the tabular valign option"
i = 0
while True:
i = find_token(document.body, "\\begin_inset Tabular", i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of tabular.")
i = j
continue
k = find_token(document.body, "<features tabularvalignment=", i)
if k == -1:
i = j
continue
# which valignment is specified?
tabularvalignment_re = re.compile(r'<features tabularvalignment="(top|bottom)">')
m = tabularvalignment_re.match(document.body[k])
if not m:
i = j
continue
tabularvalignment = m.group(1)
subst = ['\\end_layout', '\\end_inset']
document.body[j+1:j+1] = subst # just inserts those lines
subst = ['\\begin_inset Box Frameless',
'position "' + tabularvalignment[0] +'"',
'hor_pos "c"',
'has_inner_box 1',
'inner_pos "c"',
'use_parbox 0',
'width "0col%"',
'special "none"',
'height "1in"',
'height_special "totalheight"',
'status open',
'',
'\\begin_layout Plain Layout']
document.body[i:i] = subst # this just inserts the array at i
i += len(subst) + 2 # adjust i to save a few cycles
def revert_phantom(document):
'Reverts phantom to ERT'
i = 0
j = 0
while True:
i = find_token(document.body, "\\begin_inset Phantom Phantom", i)
if i == -1:
return
substi = document.body[i].replace('\\begin_inset Phantom Phantom', \
'\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n\n\\backslash\n' \
'phantom{\n\\end_layout\n\n\\end_inset\n')
substi = substi.split('\n')
document.body[i : i+4] = substi
i += len(substi)
j = find_token(document.body, "\\end_layout", i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of Phantom inset.")
return
substj = document.body[j].replace('\\end_layout', \
'\\size default\n\n\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n' \
'}\n\\end_layout\n\n\\end_inset\n')
substj = substj.split('\n')
document.body[j : j+4] = substj
i += len(substj)
def revert_hphantom(document):
'Reverts hphantom to ERT'
i = 0
j = 0
while True:
i = find_token(document.body, "\\begin_inset Phantom HPhantom", i)
if i == -1:
return
substi = document.body[i].replace('\\begin_inset Phantom HPhantom', \
'\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n\n\\backslash\n' \
'hphantom{\n\\end_layout\n\n\\end_inset\n')
substi = substi.split('\n')
document.body[i : i+4] = substi
i += len(substi)
j = find_token(document.body, "\\end_layout", i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of HPhantom inset.")
return
substj = document.body[j].replace('\\end_layout', \
'\\size default\n\n\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n' \
'}\n\\end_layout\n\n\\end_inset\n')
substj = substj.split('\n')
document.body[j : j+4] = substj
i += len(substj)
def revert_vphantom(document):
'Reverts vphantom to ERT'
i = 0
j = 0
while True:
i = find_token(document.body, "\\begin_inset Phantom VPhantom", i)
if i == -1:
return
substi = document.body[i].replace('\\begin_inset Phantom VPhantom', \
'\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n\n\\backslash\n' \
'vphantom{\n\\end_layout\n\n\\end_inset\n')
substi = substi.split('\n')
document.body[i : i+4] = substi
i += len(substi)
j = find_token(document.body, "\\end_layout", i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of VPhantom inset.")
return
substj = document.body[j].replace('\\end_layout', \
'\\size default\n\n\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Plain Layout\n\n' \
'}\n\\end_layout\n\n\\end_inset\n')
substj = substj.split('\n')
document.body[j : j+4] = substj
i += len(substj)
##
# Conversion hub
@ -99,10 +185,12 @@ def revert_tabularvalign(document):
supported_versions = ["2.0.0","2.0"]
convert = [[346, []],
[347, []]
[347, []],
[348, []]
]
revert = [[346, [revert_tabularvalign]],
revert = [[347, [revert_phantom, revert_hphantom, revert_vphantom]],
[346, [revert_tabularvalign]],
[345, [revert_swiss]]
]

View File

@ -164,6 +164,17 @@ Menuset
Item "Dissolve Inset|D" "inset-dissolve"
End
#
# InsetPhantom context menu
#
Menu "context-phantom"
Item "Phantom" "next-inset-modify phantom Phantom Phantom"
Item "Horiz. Phantom" "next-inset-modify phantom Phantom HPhantom"
Item "Vert. Phantom" "next-inset-modify phantom Phantom VPhantom"
Separator
Item "Dissolve Inset|D" "inset-dissolve"
End
#
# InsetSpace context menu

View File

@ -375,6 +375,7 @@ Menuset
Item "Horizontal Space...|o" "dialog-show-new-inset space"
Item "Horizontal Line|L" "line-insert"
Item "Vertical Space...|V" "dialog-show-new-inset vspace"
Submenu "Phantom Text" "insert_phantom"
Separator
Item "Hyphenation Point|H" "specialchar-insert hyphenation"
Item "Ligature Break|k" "specialchar-insert ligature-break"
@ -443,6 +444,12 @@ Menuset
Menu "insert_branches"
Branches
End
Menu "insert_phantom"
Item "Phantom" "phantom-insert Phantom"
Item "Horiz. Phantom" "phantom-insert HPhantom"
Item "Vert. Phantom" "phantom-insert VPhantom"
End
Menu "insert_custom"
Custom

View File

@ -118,7 +118,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 347; // vfr: add tabular valign opion
int const LYX_FORMAT = 348; // uwestoehr: add support for \*phantom
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -993,6 +993,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
case WRAP_CODE:
case NOTE_CODE:
case BRANCH_CODE:
case PHANTOM_CODE:
case BOX_CODE:
case LISTINGS_CODE:
enable = (cmd.argument().empty() ||

View File

@ -119,6 +119,7 @@ ColorSet::ColorSet()
{ Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
{ Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "greyedout" },
{ Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
{ Color_phantomtext, N_("phantom inset text"), "phantomtext", grey80, "phantomtext" },
{ Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" },
{ Color_listingsbg, N_("listings background"), "listingsbg", "white", "listingsbg" },
{ Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "branchlabel" },

View File

@ -80,6 +80,8 @@ enum ColorCode
Color_indexlabel,
/// Label color for margin notes
Color_marginlabel,
/// Text color for phantom insets
Color_phantomtext,
/// Label color for URL insets
Color_urllabel,

View File

@ -417,6 +417,7 @@ enum FuncCode
LFUN_COPY_LABEL_AS_REF, // sts, 20081116
LFUN_VC_COMMAND,
LFUN_MATH_FONT_STYLE,
LFUN_PHANTOM_INSERT, // uwestoehr, 20090130
LFUN_LASTACTION // end of the table
};

View File

@ -573,6 +573,16 @@ void LyXAction::init()
* \endvar
*/
{ LFUN_NOTES_MUTATE, "notes-mutate", Argument, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_PHANTOM_INSERT
* \li Action: Inserts phantom on the current cursor postion,
move selection inside the inset.
* \li Syntax: phantom-insert [<TYPE>]
* \li Params: <TYPE>: <Phantom|HPhantom|VPhantom> default: Phantom
* \li Origin: uwestoehr, 30 Jan 2009
* \endvar
*/
{ LFUN_PHANTOM_INSERT, "phantom-insert", Noop, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_NEWLINE_INSERT
* \li Action: Inserts a line break or new line.
@ -582,7 +592,6 @@ void LyXAction::init()
* \endvar
*/
{ LFUN_NEWLINE_INSERT, "newline-insert", Noop, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_ESCAPE
* \li Action: Clears the selection. If no text is selected call #LFUN_FINISHED_FORWARD.

View File

@ -66,6 +66,7 @@
#include "insets/InsetInclude.h"
#include "insets/InsetListings.h"
#include "insets/InsetNote.h"
#include "insets/InsetPhantom.h"
#include "insets/InsetSpace.h"
#include "insets/InsetTabular.h"
#include "insets/InsetVSpace.h"
@ -1245,6 +1246,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
data = InsetNote::params2string(p);
break;
}
case PHANTOM_CODE: {
InsetPhantomParams p;
data = InsetPhantom::params2string(p);
break;
}
case SPACE_CODE: {
InsetSpaceParams p;
data = InsetSpace::params2string(p);

View File

@ -513,6 +513,7 @@ SOURCEFILESINSETS = \
insets/InsetNomencl.cpp \
insets/InsetNote.cpp \
insets/InsetOptArg.cpp \
insets/InsetPhantom.cpp \
insets/InsetQuotes.cpp \
insets/InsetRef.cpp \
insets/InsetSpace.cpp \
@ -566,6 +567,7 @@ HEADERFILESINSETS = \
insets/InsetNomencl.h \
insets/InsetNote.h \
insets/InsetOptArg.h \
insets/InsetPhantom.h \
insets/InsetQuotes.h \
insets/InsetRef.h \
insets/InsetSpace.h \

View File

@ -1445,6 +1445,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_FLEX_INSERT:
case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT:
case LFUN_PHANTOM_INSERT:
case LFUN_ERT_INSERT:
case LFUN_LISTING_INSERT:
case LFUN_MARGINALNOTE_INSERT:
@ -2004,6 +2005,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
code = LABEL_CODE;
else if (cmd.argument() == "note")
code = NOTE_CODE;
else if (cmd.argument() == "phantom")
code = PHANTOM_CODE;
else if (cmd.argument() == "ref")
code = REF_CODE;
else if (cmd.argument() == "space")
@ -2082,6 +2085,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
if (cur.buffer()->masterBuffer()->params().branchlist().empty())
enable = false;
break;
case LFUN_PHANTOM_INSERT:
code = PHANTOM_CODE;
break;
case LFUN_LABEL_INSERT:
code = LABEL_CODE;
break;

View File

@ -44,6 +44,7 @@
#include "insets/InsetNote.h"
#include "insets/InsetBox.h"
#include "insets/InsetBranch.h"
#include "insets/InsetPhantom.h"
#include "insets/InsetOptArg.h"
#include "insets/InsetNewpage.h"
#include "insets/InsetRef.h"
@ -126,6 +127,13 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
return new InsetBranch(buf, InsetBranchParams(arg));
}
case LFUN_PHANTOM_INSERT: {
string arg = cmd.getArg(0);
if (arg.empty())
arg = "Phantom";
return new InsetPhantom(buf, arg);
}
case LFUN_ERT_INSERT:
return new InsetERT(buf);
@ -523,6 +531,8 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
inset.reset(new InsetFlex(buf, s));
} else if (tmptok == "Branch") {
inset.reset(new InsetBranch(buf, InsetBranchParams()));
} else if (tmptok == "Phantom") {
inset.reset(new InsetPhantom(buf, tmptok));
} else if (tmptok == "ERT") {
inset.reset(new InsetERT(buf));
} else if (tmptok == "listings") {

View File

@ -70,6 +70,7 @@ static TranslatorMap const build_translator()
InsetName("ending", ENDING_CODE),
InsetName("label", LABEL_CODE),
InsetName("note", NOTE_CODE),
InsetName("phantom", PHANTOM_CODE),
InsetName("accent", ACCENT_CODE),
InsetName("math", MATH_CODE),
InsetName("index", INDEX_CODE),

View File

@ -112,6 +112,8 @@ enum InsetCode {
INFO_CODE, // 45
///
COLLAPSABLE_CODE,
///
PHANTOM_CODE,
};
} // namespace lyx

View File

@ -683,6 +683,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_NOTE_INSERT:
case LFUN_NOTE_NEXT:
case LFUN_OPTIONAL_INSERT:
case LFUN_PHANTOM_INSERT:
case LFUN_REFERENCE_NEXT:
case LFUN_SERVER_GOTO_FILE_ROW:
case LFUN_SERVER_NOTIFY:

388
src/insets/InsetPhantom.cpp Normal file
View File

@ -0,0 +1,388 @@
/**
* \file InsetPhantom.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetPhantom.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "BufferParams.h"
#include "Counters.h"
#include "Cursor.h"
#include "Dimension.h"
#include "DispatchResult.h"
#include "Exporter.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetIterator.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
#include "TextClass.h"
#include "support/docstream.h"
#include "support/gettext.h"
#include "support/Translator.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <algorithm>
#include <sstream>
using namespace std;
namespace lyx {
namespace {
typedef Translator<string, InsetPhantomParams::Type> PhantomTranslator;
typedef Translator<docstring, InsetPhantomParams::Type> PhantomTranslatorLoc;
PhantomTranslator const init_phantomtranslator()
{
PhantomTranslator translator("Phantom", InsetPhantomParams::Phantom);
translator.addPair("HPhantom", InsetPhantomParams::HPhantom);
translator.addPair("VPhantom", InsetPhantomParams::VPhantom);
return translator;
}
PhantomTranslatorLoc const init_phantomtranslator_loc()
{
PhantomTranslatorLoc translator(_("Phantom"), InsetPhantomParams::Phantom);
translator.addPair(_("HPhantom"), InsetPhantomParams::HPhantom);
translator.addPair(_("VPhantom"), InsetPhantomParams::VPhantom);
return translator;
}
PhantomTranslator const & phantomtranslator()
{
static PhantomTranslator translator = init_phantomtranslator();
return translator;
}
PhantomTranslatorLoc const & phantomtranslator_loc()
{
static PhantomTranslatorLoc translator = init_phantomtranslator_loc();
return translator;
}
} // anon
InsetPhantomParams::InsetPhantomParams()
: type(Phantom)
{}
void InsetPhantomParams::write(ostream & os) const
{
string const label = phantomtranslator().find(type);
os << "Phantom " << label << "\n";
}
void InsetPhantomParams::read(Lexer & lex)
{
string label;
lex >> label;
if (lex)
type = phantomtranslator().find(label);
}
/////////////////////////////////////////////////////////////////////
//
// InsetPhantom
//
/////////////////////////////////////////////////////////////////////
InsetPhantom::InsetPhantom(Buffer const & buf, string const & label)
: InsetCollapsable(buf)
{
params_.type = phantomtranslator().find(label);
}
InsetPhantom::~InsetPhantom()
{
hideDialogs("phantom", this);
}
docstring InsetPhantom::editMessage() const
{
return _("Opened Phantom Inset");
}
docstring InsetPhantom::name() const
{
return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
}
Inset::DisplayType InsetPhantom::display() const
{
return Inline;
}
void InsetPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetText::metrics(mi, dim);
// cache the inset dimension
setDimCache(mi, dim);
}
void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
{
// draw the text
InsetText::draw(pi, x, y);
// draw the arrow(s)
static int const arrow_size = 4;
ColorCode const origcol = pi.base.font.color();
pi.base.font.setColor(Color_special);
pi.base.font.setColor(origcol);
Dimension const dim = dimension(*pi.base.bv);
if (params_.type == InsetPhantomParams::Phantom ||
params_.type == InsetPhantomParams::VPhantom) {
// y1---------
// / \.
// y2----- / | \.
// |
// |
// y3----- \ | /
// \ /
// y4---------
// | | |
// / | \.
// x1 x2 x3
int const x2 = x + dim.wid / 2;
int const x1 = x2 - arrow_size;
int const x3 = x2 + arrow_size;
int const y1 = y - dim.asc;
int const y2 = y1 + arrow_size;
int const y4 = y + dim.des;
int const y3 = y4 - arrow_size;
// top arrow
pi.pain.line(x2, y1, x1, y2, Color_added_space);
pi.pain.line(x2, y1, x3, y2, Color_added_space);
// bottom arrow
pi.pain.line(x2, y4, x1, y3, Color_added_space);
pi.pain.line(x2, y4, x3, y3, Color_added_space);
// joining line
pi.pain.line(x2, y1, x2, y4, Color_added_space);
}
if (params_.type == InsetPhantomParams::Phantom ||
params_.type == InsetPhantomParams::HPhantom) {
// y1---- / \.
// / \.
// y2--- <---------------->
// \ /
// y3---- \ /
// | | | |
// x1 x2 x3 x4
int const x1 = x;
int const x2 = x + arrow_size;
int const x4 = x + dim.wid;
int const x3 = x4 - arrow_size;
int const y2 = y + (dim.des - dim.asc) / 2;
int const y1 = y2 - arrow_size;
int const y3 = y2 + arrow_size;
// left arrow
pi.pain.line(x1, y2, x2, y3, Color_added_space);
pi.pain.line(x1, y2, x2, y1, Color_added_space);
// right arrow
pi.pain.line(x4, y2, x3, y3, Color_added_space);
pi.pain.line(x4, y2, x3, y1, Color_added_space);
// joining line
pi.pain.line(x1, y2, x4, y2, Color_added_space);
}
drawMarkers(pi, x, y);
}
void InsetPhantom::write(ostream & os) const
{
params_.write(os);
InsetCollapsable::write(os);
}
void InsetPhantom::read(Lexer & lex)
{
params_.read(lex);
InsetCollapsable::read(lex);
}
void InsetPhantom::setButtonLabel()
{
docstring const label = phantomtranslator_loc().find(params_.type);
setLabel(label);
}
bool InsetPhantom::showInsetDialog(BufferView * bv) const
{
bv->showDialog("phantom", params2string(params()),
const_cast<InsetPhantom *>(this));
return true;
}
void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY:
string2params(to_utf8(cmd.argument()), params_);
setLayout(buffer().params());
break;
case LFUN_INSET_DIALOG_UPDATE:
cur.bv().updateDialog("phantom", params2string(params()));
break;
default:
InsetCollapsable::doDispatch(cur, cmd);
break;
}
}
bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
switch (cmd.action) {
case LFUN_INSET_MODIFY:
flag.setEnabled(true);
return true;
case LFUN_INSET_DIALOG_UPDATE:
flag.setEnabled(true);
return true;
default:
return InsetCollapsable::getStatus(cur, cmd, flag);
}
}
int InsetPhantom::latex(odocstream & os, OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
if (params_.type == InsetPhantomParams::Phantom)
os << "\\phantom{";
else if (params_.type == InsetPhantomParams::HPhantom)
os << "\\hphantom{";
else if (params_.type == InsetPhantomParams::VPhantom)
os << "\\vphantom{";
int const i = InsetText::latex(os, runparams);
os << "}";
runparams_in.encoding = runparams.encoding;
return i + 2;
}
int InsetPhantom::plaintext(odocstream & os,
OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
if (params_.type == InsetPhantomParams::Phantom)
os << '[' << buffer().B_("phantom") << ":";
else if (params_.type == InsetPhantomParams::HPhantom)
os << '[' << buffer().B_("hphantom") << ":";
else if (params_.type == InsetPhantomParams::VPhantom)
os << '[' << buffer().B_("vphantom") << ":";
InsetText::plaintext(os, runparams);
os << "]";
return PLAINTEXT_NEWLINE;
}
int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
string cmdname;
if (params_.type == InsetPhantomParams::Phantom)
cmdname = "phantom";
else if (params_.type == InsetPhantomParams::HPhantom)
cmdname = "phantom";
else if (params_.type == InsetPhantomParams::VPhantom)
cmdname = "phantom";
os << "<" + cmdname + ">";
int const i = InsetText::docbook(os, runparams);
os << "</" + cmdname + ">";
return i;
}
docstring InsetPhantom::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-phantom");
}
string InsetPhantom::params2string(InsetPhantomParams const & params)
{
ostringstream data;
data << "phantom" << ' ';
params.write(data);
return data.str();
}
void InsetPhantom::string2params(string const & in, InsetPhantomParams & params)
{
params = InsetPhantomParams();
if (in.empty())
return;
istringstream data(in);
Lexer lex;
lex.setStream(data);
lex.setContext("InsetPhantom::string2params");
lex >> "phantom" >> "Phantom";
params.read(lex);
}
} // namespace lyx

108
src/insets/InsetPhantom.h Normal file
View File

@ -0,0 +1,108 @@
// -*- C++ -*-
/**
* \file InsetPhantom.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#ifndef INSET_PHANTOM_H
#define INSET_PHANTOM_H
#include "InsetCollapsable.h"
namespace lyx {
class InsetPhantomParams
{
public:
enum Type {
Phantom,
HPhantom,
VPhantom
};
/// \c type defaults to Phantom
InsetPhantomParams();
///
void write(std::ostream & os) const;
///
void read(Lexer & lex);
///
Type type;
};
/////////////////////////////////////////////////////////////////////////
//
// InsetPhantom
//
/////////////////////////////////////////////////////////////////////////
/// The PostIt phantom inset, and other annotations
class InsetPhantom : public InsetCollapsable
{
public:
///
InsetPhantom(Buffer const &, std::string const &);
///
~InsetPhantom();
///
static std::string params2string(InsetPhantomParams const &);
///
static void string2params(std::string const &, InsetPhantomParams &);
///
InsetPhantomParams const & params() const { return params_; }
private:
///
docstring editMessage() const;
///
InsetCode lyxCode() const { return PHANTOM_CODE; }
///
docstring name() const;
///
DisplayType display() const;
///
bool noFontChange() const { return params_.type != InsetPhantomParams::Phantom; }
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
void write(std::ostream &) const;
///
void read(Lexer & lex);
///
void setButtonLabel();
/// show the phantom dialog
bool showInsetDialog(BufferView * bv) const;
///
int latex(odocstream &, OutputParams const &) const;
///
int plaintext(odocstream &, OutputParams const &) const;
///
int docbook(odocstream &, OutputParams const &) const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
Inset * clone() const { return new InsetPhantom(*this); }
/// used by the constructors
void init();
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
///
friend class InsetPhantomParams;
///
InsetPhantomParams params_;
};
} // namespace lyx
#endif // INSET_PHANTOM_H

View File

@ -3943,6 +3943,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_OPTIONAL_INSERT:
case LFUN_BOX_INSERT:
case LFUN_BRANCH_INSERT:
case LFUN_PHANTOM_INSERT:
case LFUN_WRAP_INSERT:
case LFUN_ERT_INSERT: {
if (cur.selIsMultiCell()) {