Add more Float tags to allow to disable wide and sideways feature

Fixes: #9557, #9558

This is amended to yesterday's layout format change.
This commit is contained in:
Juergen Spitzmueller 2015-05-22 18:59:17 +02:00
parent 7760c5ccf2
commit 47dd9189eb
10 changed files with 222 additions and 24 deletions

View File

@ -15585,7 +15585,7 @@ to your layout file.
\begin_layout Description
\change_inserted -712698321 1432283705
\change_inserted -712698321 1432313622
\begin_inset Flex Code
status collapsed
@ -15690,6 +15690,140 @@ ignore LaTeX rules
none
\emph default
.
\end_layout
\begin_layout Description
\change_inserted -712698321 1432313755
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313630
AllowsSideways
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313646
\emph off
0
\end_layout
\end_inset
,
\begin_inset space \thinspace{}
\end_inset
\emph on
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313646
\emph on
1
\end_layout
\end_inset
\emph default
] Defines whether the float allows to be rotated via the rotfloat package
(sidewaysfloat).
Set to
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313721
0
\end_layout
\end_inset
if the float does not support this feature.
\end_layout
\begin_layout Description
\change_inserted -712698321 1432313802
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313759
AllowsWide
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313755
\emph off
0
\end_layout
\end_inset
,
\begin_inset space \thinspace{}
\end_inset
\emph on
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313755
\emph on
1
\end_layout
\end_inset
\emph default
] Defines whether the float has a starred variant that spans columns in
a two column paragraph.
Set to
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1432313755
0
\end_layout
\end_inset
if the float does not support this feature.
\change_unchanged
\end_layout

View File

@ -184,7 +184,7 @@ import os, re, string, sys
# New InsetLayout and Layout tags "PassThruChars"
# Incremented to format 56, 20 May 2015 by spitz
# New Float tags "AllowedPlacement"
# New Float tags "AllowedPlacement", "AllowsWide", "AllowsSideways"
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").

View File

@ -64,6 +64,24 @@ bool FloatList::typeExist(string const & t) const
}
bool FloatList::allowsWide(string const & t) const
{
List::const_iterator cit = list.find(t);
if (cit != list.end())
return cit->second.allowsWide();
return false;
}
bool FloatList::allowsSideways(string const & t) const
{
List::const_iterator cit = list.find(t);
if (cit != list.end())
return cit->second.allowsSideways();
return false;
}
Floating const & FloatList::getType(string const & t) const
{
// I wish we could use exceptions

View File

@ -43,6 +43,10 @@ public:
///
bool typeExist(std::string const & t) const;
///
bool allowsWide(std::string const & t) const;
///
bool allowsSideways(std::string const & t) const;
///
Floating const & getType(std::string const & t) const;
///
void erase(std::string const & t);

View File

@ -30,11 +30,13 @@ Floating::Floating(string const & type, string const & placement,
string const & listName, std::string const & listCmd,
string const & refPrefix, std::string const & allowedplacement,
string const & htmlTag, string const & htmlAttrib,
string const & htmlStyle, bool usesfloat, bool ispredefined)
string const & htmlStyle, bool usesfloat, bool ispredefined,
bool allowswide, bool allowssideways)
: floattype_(type), placement_(placement), ext_(ext), within_(within),
style_(style), name_(name), listname_(listName), listcommand_(listCmd),
refprefix_(refPrefix), allowedplacement_(allowedplacement),
usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
allowswide_(allowswide), allowssideways_(allowssideways),
html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle)
{}

View File

@ -26,7 +26,8 @@ namespace lyx {
class Floating {
public:
///
Floating() : usesfloatpkg_(false), ispredefined_(false) {}
Floating() : usesfloatpkg_(false), ispredefined_(false),
allowswide_(true), allowssideways_(true) {}
///
Floating(std::string const & type, std::string const & placement,
std::string const & ext, std::string const & within,
@ -34,7 +35,8 @@ public:
std::string const & listName, std::string const & listCmd,
std::string const & refPrefix, std::string const & allowedplacement,
std::string const & htmlType, std::string const & htmlClass,
std::string const & htmlStyle, bool usesfloat, bool isprefined);
std::string const & htmlStyle, bool usesfloat, bool isprefined,
bool allowswide, bool allowssideways);
///
std::string const & floattype() const { return floattype_; }
///
@ -62,6 +64,10 @@ public:
bool usesFloatPkg() const { return usesfloatpkg_; }
///
bool isPredefined() const { return ispredefined_; }
///
bool allowsWide() const { return allowswide_; }
///
bool allowsSideways() const { return allowssideways_; }
/// style information, for preamble
std::string const & htmlStyle() const { return html_style_; }
/// class, for css, defaults to "float-" + type()
@ -95,6 +101,10 @@ private:
bool usesfloatpkg_;
///
bool ispredefined_;
///
bool allowswide_;
///
bool allowssideways_;
///
mutable std::string html_tag_;
///

View File

@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files.
//
int const LAYOUT_FORMAT = 56; //spitz: New Float tags AllowedPlacement
int const LAYOUT_FORMAT = 56; //spitz: New Float tags AllowedPlacement, AllowsWide, AllowsSideways
namespace {
@ -1098,11 +1098,15 @@ bool TextClass::readFloat(Lexer & lexrc)
FT_LISTCOMMAND,
FT_REFPREFIX,
FT_ALLOWED_PLACEMENT,
FT_ALLOWS_SIDEWAYS,
FT_ALLOWS_WIDE,
FT_END
};
LexerKeyword floatTags[] = {
{ "allowedplacement", FT_ALLOWED_PLACEMENT },
{ "allowssideways", FT_ALLOWS_SIDEWAYS },
{ "allowswide", FT_ALLOWS_WIDE },
{ "end", FT_END },
{ "extension", FT_EXT },
{ "guiname", FT_NAME },
@ -1137,6 +1141,8 @@ bool TextClass::readFloat(Lexer & lexrc)
string within;
bool usesfloat = true;
bool ispredefined = false;
bool allowswide = true;
bool allowssideways = true;
bool getout = false;
while (!getout && lexrc.isOK()) {
@ -1212,6 +1218,14 @@ bool TextClass::readFloat(Lexer & lexrc)
lexrc.next();
ispredefined = lexrc.getBool();
break;
case FT_ALLOWS_SIDEWAYS:
lexrc.next();
allowssideways = lexrc.getBool();
break;
case FT_ALLOWS_WIDE:
lexrc.next();
allowswide = lexrc.getBool();
break;
case FT_HTMLATTR:
lexrc.next();
htmlattr = lexrc.getString();
@ -1252,8 +1266,9 @@ bool TextClass::readFloat(Lexer & lexrc)
"not be able to produce a float list.");
}
Floating fl(type, placement, ext, within, style, name,
listname, listcommand, refprefix, allowed_placement,
htmltag, htmlattr, htmlstyle, usesfloat, ispredefined);
listname, listcommand, refprefix, allowed_placement,
htmltag, htmlattr, htmlstyle, usesfloat, ispredefined,
allowswide, allowssideways);
floatlist_.newFloat(fl);
// each float has its own counter
counters_.newCounter(from_ascii(type), from_ascii(within),

View File

@ -146,13 +146,15 @@ void FloatPlacement::paramsToDialog(Inset const * inset)
InsetFloatParams const & params = fl->params();
BufferParams const & bp = fl->buffer().params();
initFloatTypeCO(bp.documentClass().floats());
FloatList const & floats = bp.documentClass().floats();
initFloatTypeCO(floats);
int const item = floatTypeCO->findData(toqstr(params.type));
floatTypeCO->setCurrentIndex(item);
allowed_placement_ =
bp.documentClass().floats().allowedPlacement(params.type);
allowed_placement_ = floats.allowedPlacement(params.type);
allows_sideways_ = floats.allowsSideways(params.type);
allows_wide_ = floats.allowsWide(params.type);
set(params.placement);
@ -165,10 +167,9 @@ void FloatPlacement::paramsToDialog(Inset const * inset)
bottomCB->setChecked(false);
}
spanCB->setChecked(params.wide);
sidewaysCB->setChecked(params.sideways);
// the package rotfloat only has *-versions for figure and table
spanCB->setEnabled(!params.sideways || standardfloat_);
spanCB->setChecked(params.wide && allows_wide_);
sidewaysCB->setChecked(params.sideways && allows_sideways_);
checkAllowed();
}
@ -255,7 +256,8 @@ void FloatPlacement::checkAllowed() const
&& contains(allowed_placement_, 'H'));
ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely
&& contains(allowed_placement_, '!'));
spanCB->setEnabled(!sideways || standardfloat_);
spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_));
sidewaysCB->setEnabled(allows_sideways_);
} else {
topCB->setEnabled(!defaults && !heredefinitely);
bottomCB->setEnabled(!defaults && !heredefinitely);

View File

@ -67,6 +67,10 @@ private:
///
std::string allowed_placement_;
///
bool allows_wide_;
///
bool allows_sideways_;
///
FloatList const * float_list_;
};

View File

@ -358,11 +358,12 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
FloatList const & floats = buffer().params().documentClass().floats();
string tmptype = params_.type;
if (params_.sideways)
if (params_.sideways && floats.allowsSideways(params_.type))
tmptype = "sideways" + params_.type;
if (params_.wide && (!params_.sideways ||
params_.type == "figure" ||
params_.type == "table"))
if (params_.wide && floats.allowsSideways(params_.type)
&& (!params_.sideways ||
params_.type == "figure" ||
params_.type == "table"))
tmptype += "*";
// Figure out the float placement to use.
// From lowest to highest:
@ -449,7 +450,10 @@ bool InsetFloat::insetAllowed(InsetCode code) const
void InsetFloat::setWide(bool w, bool update_label)
{
params_.wide = w;
if (!buffer().params().documentClass().floats().allowsWide(params_.type))
params_.wide = false;
else
params_.wide = w;
if (update_label)
setNewLabel();
}
@ -457,7 +461,10 @@ void InsetFloat::setWide(bool w, bool update_label)
void InsetFloat::setSideways(bool s, bool update_label)
{
params_.sideways = s;
if (!buffer().params().documentClass().floats().allowsSideways(params_.type))
params_.sideways = false;
else
params_.sideways = s;
if (update_label)
setNewLabel();
}
@ -480,10 +487,12 @@ void InsetFloat::setNewLabel()
lab += floatName(params_.type);
if (params_.wide)
FloatList const & floats = buffer().params().documentClass().floats();
if (params_.wide && floats.allowsWide(params_.type))
lab += '*';
if (params_.sideways)
if (params_.sideways && floats.allowsSideways(params_.type))
lab += _(" (sideways)");
setLabel(lab);