Uwe reminded me that I did not implement a protected horizontal fill
(\hspace*{\fill}). The attached patch does this.
I'll commit if I get no objections.
Jürgen
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py (Revision 23787)
+++ lib/lyx2lyx/LyX.py (Arbeitskopie)
@@ -80,7 +80,7 @@
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 2)),
- ("1_6", range(277,320), minor_versions("1.6" , 0))]
+ ("1_6", range(277,321), minor_versions("1.6" , 0))]
def formats_list():
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py (Revision 23794)
+++ lib/lyx2lyx/lyx_1_6.py (Arbeitskopie)
@@ -1458,6 +1458,24 @@
'hspace{' + length + '}\n\\end_layout\n\n\\end_inset\n\n')
+def revert_protected_hfill(document):
+ ' Revert \\begin_inset Space \\hspace*{\\fill} to ERT '
+ i = 0
+ while True:
+ i = find_token(document.body, '\\begin_inset Space \\hspace*{\\fill}', 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 space inset.")
+ continue
+ del document.body[j]
+ document.body[i] = document.body[i].replace('\\begin_inset Space \\hspace*{\\fill}', \
+ '\\begin_inset ERT\nstatus collapsed\n\n' \
+ '\\begin_layout Standard\n\n\n\\backslash\n' \
+ 'hspace*{\n\\backslash\nfill}\n\\end_layout\n\n\\end_inset\n\n')
+
+
##
# Conversion hub
#
@@ -1505,10 +1523,12 @@
[316, [convert_subfig]],
[317, []],
[318, []],
- [319, [convert_spaceinset, convert_hfill]]
+ [319, [convert_spaceinset, convert_hfill]],
+ [320, []]
]
-revert = [[318, [revert_spaceinset, revert_hfills, revert_hspace]],
+revert = [[319, [revert_protected_hfill]],
+ [318, [revert_spaceinset, revert_hfills, revert_hspace]],
[317, [remove_extra_embedded_files]],
[316, [revert_wrapplacement]],
[315, [revert_subfig]],
Index: src/insets/InsetSpace.cpp
===================================================================
--- src/insets/InsetSpace.cpp (Revision 23787)
+++ src/insets/InsetSpace.cpp (Arbeitskopie)
@@ -96,6 +96,9 @@
case InsetSpaceParams::HFILL:
message = _("Horizontal Fill");
break;
+ case InsetSpaceParams::HFILL_PROTECTED:
+ message = _("Protected Horizontal Fill");
+ break;
case InsetSpaceParams::DOTFILL:
message = _("Horizontal Fill (Dots)");
break;
@@ -141,9 +144,7 @@
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{
- if (params_.kind == InsetSpaceParams::HFILL ||
- params_.kind == InsetSpaceParams::DOTFILL ||
- params_.kind == InsetSpaceParams::HRULEFILL) {
+ if (isStretchableSpace()) {
// The metrics for this kinds are calculated externally in
// \c TextMetrics::computeRowMetrics. Those are dummy value:
dim = Dimension(10, 10, 10);
@@ -178,6 +179,7 @@
dim.wid = params_.length.inBP();
break;
case InsetSpaceParams::HFILL:
+ case InsetSpaceParams::HFILL_PROTECTED:
case InsetSpaceParams::DOTFILL:
case InsetSpaceParams::HRULEFILL:
// shut up compiler
@@ -192,9 +194,7 @@
{
Dimension const dim = dimension(*pi.base.bv);
- if (params_.kind == InsetSpaceParams::HFILL ||
- params_.kind == InsetSpaceParams::DOTFILL ||
- params_.kind == InsetSpaceParams::HRULEFILL) {
+ if (isStretchableSpace()) {
int const asc = theFontMetrics(pi.base.font).ascent('M');
int const desc = theFontMetrics(pi.base.font).descent('M');
int const x0 = x + 1;
@@ -208,6 +208,11 @@
pi.pain.line(x0, y2 , x1, y2, Color_added_space,
frontend::Painter::line_onoffdash);
pi.pain.line(x1, y1, x1, y0, Color_added_space);
+ } else if (params_.kind == InsetSpaceParams::HFILL_PROTECTED) {
+ pi.pain.line(x0, y1, x0, y0, Color_latex);
+ pi.pain.line(x0, y2 , x1, y2, Color_latex,
+ frontend::Painter::line_onoffdash);
+ pi.pain.line(x1, y1, x1, y0, Color_latex);
} else if (params_.kind == InsetSpaceParams::DOTFILL) {
pi.pain.line(x0, y1, x0, y0, Color_special);
pi.pain.line(x0, y, x1, y, Color_special,
@@ -279,6 +284,9 @@
case InsetSpaceParams::HFILL:
os << "\\hfill{}";
break;
+ case InsetSpaceParams::HFILL_PROTECTED:
+ os << "\\hspace*{\\fill}";
+ break;
case InsetSpaceParams::DOTFILL:
os << "\\dotfill{}";
break;
@@ -321,6 +329,8 @@
kind = InsetSpaceParams::NEGTHIN;
else if (command == "\\hfill{}")
kind = InsetSpaceParams::HFILL;
+ else if (command == "\\hspace*{\\fill}")
+ kind = InsetSpaceParams::HFILL_PROTECTED;
else if (command == "\\dotfill{}")
kind = InsetSpaceParams::DOTFILL;
else if (command == "\\hrulefill{}")
@@ -393,6 +403,9 @@
case InsetSpaceParams::HFILL:
os << (runparams.free_spacing ? " " : "\\hfill{}");
break;
+ case InsetSpaceParams::HFILL_PROTECTED:
+ os << (runparams.free_spacing ? " " : "\\hspace*{\\fill}");
+ break;
case InsetSpaceParams::DOTFILL:
os << (runparams.free_spacing ? " " : "\\dotfill{}");
break;
@@ -420,6 +433,7 @@
{
switch (params_.kind) {
case InsetSpaceParams::HFILL:
+ case InsetSpaceParams::HFILL_PROTECTED:
os << " ";
return 5;
case InsetSpaceParams::DOTFILL:
@@ -451,6 +465,7 @@
os << " ";
break;
case InsetSpaceParams::HFILL:
+ case InsetSpaceParams::HFILL_PROTECTED:
os << '\n';
case InsetSpaceParams::DOTFILL:
// FIXME
@@ -476,6 +491,7 @@
bool InsetSpace::isStretchableSpace() const
{
return (params_.kind == InsetSpaceParams::HFILL ||
+ params_.kind == InsetSpaceParams::HFILL_PROTECTED ||
params_.kind == InsetSpaceParams::DOTFILL ||
params_.kind == InsetSpaceParams::HRULEFILL);
}
Index: src/insets/InsetSpace.h
===================================================================
--- src/insets/InsetSpace.h (Revision 23787)
+++ src/insets/InsetSpace.h (Arbeitskopie)
@@ -47,6 +47,8 @@
NEGTHIN,
/// rubber length
HFILL,
+ /// \hspace*{\fill}
+ HFILL_PROTECTED,
/// rubber length, filled with dots
DOTFILL,
/// rubber length, filled with a rule
Index: src/frontends/qt4/GuiHSpace.h
===================================================================
--- src/frontends/qt4/GuiHSpace.h (Revision 23787)
+++ src/frontends/qt4/GuiHSpace.h (Arbeitskopie)
@@ -31,6 +31,8 @@
void change_adaptor();
///
void enableWidgets(int);
+ ///
+ void patternChanged();
private:
/// Apply from dialog
Index: src/frontends/qt4/GuiHSpace.cpp
===================================================================
--- src/frontends/qt4/GuiHSpace.cpp (Revision 23787)
+++ src/frontends/qt4/GuiHSpace.cpp (Arbeitskopie)
@@ -54,7 +54,7 @@
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(fillPatternCO, SIGNAL(activated(int)),
- this, SLOT(change_adaptor()));
+ this, SLOT(patternChanged()));
valueLE->setValidator(unsignedLengthValidator(valueLE));
@@ -90,13 +90,23 @@
valueLE->setEnabled(selection == 7);
unitCO->setEnabled(selection == 7);
fillPatternCO->setEnabled(selection == 6);
+ int pattern = fillPatternCO->currentIndex();
bool const enable_keep =
- selection == 0 || selection == 3 || selection == 7;
+ selection == 0 || selection == 3 ||
+ (selection == 6 && pattern == 0) || selection == 7;
keepCB->setEnabled(enable_keep);
changed();
}
+void GuiHSpace::patternChanged()
+{
+ enableWidgets(spacingCO->currentIndex());
+ changed();
+}
+
+
+
static void setWidgetsFromHSpace(InsetSpaceParams const & params,
QComboBox * spacing,
QLineEdit * value,
@@ -137,6 +147,10 @@
case InsetSpaceParams::HFILL:
item = 6;
break;
+ case InsetSpaceParams::HFILL_PROTECTED:
+ item = 6;
+ protect = true;
+ break;
case InsetSpaceParams::DOTFILL:
item = 6;
pattern = 1;
@@ -200,6 +214,8 @@
params.kind = InsetSpaceParams::DOTFILL;
else if (fill == 2)
params.kind = InsetSpaceParams::HRULEFILL;
+ else if (keep)
+ params.kind = InsetSpaceParams::HFILL_PROTECTED;
else
params.kind = InsetSpaceParams::HFILL;
break;
Index: src/factory.cpp
===================================================================
--- src/factory.cpp (Revision 23787)
+++ src/factory.cpp (Arbeitskopie)
@@ -348,6 +348,8 @@
isp.kind = InsetSpaceParams::NEGTHIN;
else if (name == "hfill")
isp.kind = InsetSpaceParams::HFILL;
+ else if (name == "hfill*")
+ isp.kind = InsetSpaceParams::HFILL_PROTECTED;
else if (name == "dotfill")
isp.kind = InsetSpaceParams::DOTFILL;
else if (name == "hrulefill")
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (Revision 23787)
+++ src/Buffer.cpp (Arbeitskopie)
@@ -116,7 +116,7 @@
namespace {
-int const LYX_FORMAT = 319;
+int const LYX_FORMAT = 320;
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;