Re: [LyX/master] \\noindent in a paragraph that starts with \\vspace is possible

2021-10-31 Thread Jürgen Spitzmüller
Am Sonntag, dem 31.10.2021 um 11:33 +0100 schrieb Juergen Spitzmueller:
> commit f0126b9fdff2118f3e9566387bed0cb5da2df9d4
> Author: Juergen Spitzmueller 
> Date:   Sun Oct 31 11:56:53 2021 +0100
> 
>     \\noindent in a paragraph that starts with \\vspace is possible
>     
>     But the \\vspace must precede \\noindent (the latter leaves
> vmode)

Note that workarea display is not adequate here. As VSpace is a display
inset, no indentation is shown. However, the line that follows the
VSpace inset (in the same par) should actually be indented if paragraph
indentation is set.

See attached MWE (from current master).

Jürgen



vspace_indent.lyx
Description: application/lyx


signature.asc
Description: This is a digitally signed message part
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


VSpace Crash [was: import fail on working latex doc]

2010-10-31 Thread Richard Heck

On 10/31/2010 05:42 AM, Scott Otterson wrote:
Has anyone seen this problem before?  I have a short latex document 
(below the dotted line) that latex crunches without error.  However, 
when I try to import it into lyx (file--import plain latex) lyx 
manages to create a .lyx file but then hangs forever when it tries to 
read it (I've also put the output .lyx file below the dotted line).


Here's what cygwin lyx 1.6.6 sends to the command shell when it tries 
to read the .lyx file:


Warning: #LyX file created by tex2lyx 1.6.6
BufferParams::readToken(): Unknown token: default
BufferParams.cpp(2365): Unknown inputenc value `\font_roman'.
Using `auto' inst\
ead.



There is a tex2lyx issue here: For some reason, the LyX file has just:
\inputencoding
with no argument. But that's not the real issue.


I have the same problem with lyx 1.6.7 on Windows 7 and 1.6.6 on Ubuntu.


In debug mode, it crashes. I'm seeing an infinite loop in this code:

int VSpace::inPixels(BufferView const  bv) const
{
// Height of a normal line in pixels (zoom factor considered)
int const default_height = defaultRowHeight();

switch (kind_) {

case DEFSKIP:
return bv.buffer().params().getDefSkip().inPixels(bv);

It seems that bv.buffer().params().getDefSkip() is just a VSpace, and so 
this calls itself.


The cause seems to be the line:
\defskip 0.75\baselineskip
If this is changed to default, the crash disappears. I guess this 
never gets handled in the VSpace constructor?


Richard



0lyx::VSpace::inPixelsVSpace.cpp5180x006a0b0f
1lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
2lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
3lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
4lyx::TextMetrics::rowHeightTextMetrics.cpp1076
0x00677bd3
5lyx::TextMetrics::redoParagraphTextMetrics.cpp459
0x0067f1b5
6lyx::BufferView::updateMetricsBufferView.cpp2476
0x006cc4d0
7lyx::BufferView::resizeBufferView.cpp1933
0x006cc702
8lyx::frontend::GuiWorkArea::initGuiWorkArea.cpp273
0x009cd83d
9lyx::frontend::GuiWorkArea::GuiWorkAreaGuiWorkArea.cpp
2510x009ceda3
10lyx::frontend::TabWorkArea::addWorkAreaGuiWorkArea.cpp
15750x009d5964
11lyx::frontend::GuiView::addWorkAreaGuiView.cpp1152
0x009ab8be
12lyx::frontend::GuiView::setBufferGuiView.cpp1330
0x009b26aa
13lyx::frontend::GuiView::loadDocumentGuiView.cpp1819
0x009b4a93
14lyx::frontend::GuiView::openDocumentGuiView.cpp1897
0x009b7b54
15lyx::frontend::GuiApplication::dispatchGuiApplication.cpp
13300x00988b0f
16lyx::frontend::GuiApplication::dispatchGuiApplication.cpp
10960x009813b9

17lyx::dispatchLyX.cpp12280x005a2218
18lyx::frontend::Action::actionAction.cpp66
0x00a1d023
19lyx::frontend::Action::qt_metacallmoc_Action.cpp77
0x00a1d083

20QMetaObject::activateqobject.cpp32950x00313ab66606
... More




fail.lyx
Description: application/lyx


VSpace Crash [was: import fail on working latex doc]

2010-10-31 Thread Richard Heck

On 10/31/2010 05:42 AM, Scott Otterson wrote:
Has anyone seen this problem before?  I have a short latex document 
(below the dotted line) that latex crunches without error.  However, 
when I try to import it into lyx (file-->import plain latex) lyx 
manages to create a .lyx file but then hangs forever when it tries to 
read it (I've also put the output .lyx file below the dotted line).


Here's what cygwin lyx 1.6.6 sends to the command shell when it tries 
to read the .lyx file:


Warning: #LyX file created by tex2lyx 1.6.6
BufferParams::readToken(): Unknown token: default
BufferParams.cpp(2365): Unknown inputenc value `\font_roman'.
Using `auto' inst\
ead.



There is a tex2lyx issue here: For some reason, the LyX file has just:
\inputencoding
with no argument. But that's not the real issue.


I have the same problem with lyx 1.6.7 on Windows 7 and 1.6.6 on Ubuntu.


In debug mode, it crashes. I'm seeing an infinite loop in this code:

int VSpace::inPixels(BufferView const & bv) const
{
// Height of a normal line in pixels (zoom factor considered)
int const default_height = defaultRowHeight();

switch (kind_) {

case DEFSKIP:
return bv.buffer().params().getDefSkip().inPixels(bv);

It seems that bv.buffer().params().getDefSkip() is just a VSpace, and so 
this calls itself.


The cause seems to be the line:
\defskip 0.75\baselineskip
If this is changed to "default", the crash disappears. I guess this 
never gets handled in the VSpace constructor?


Richard



0lyx::VSpace::inPixelsVSpace.cpp5180x006a0b0f
1lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
2lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
3lyx::VSpace::inPixelsVSpace.cpp5180x006a0b32
4lyx::TextMetrics::rowHeightTextMetrics.cpp1076
0x00677bd3
5lyx::TextMetrics::redoParagraphTextMetrics.cpp459
0x0067f1b5
6lyx::BufferView::updateMetricsBufferView.cpp2476
0x006cc4d0
7lyx::BufferView::resizeBufferView.cpp1933
0x006cc702
8lyx::frontend::GuiWorkArea::initGuiWorkArea.cpp273
0x009cd83d
9lyx::frontend::GuiWorkArea::GuiWorkAreaGuiWorkArea.cpp
2510x009ceda3
10lyx::frontend::TabWorkArea::addWorkAreaGuiWorkArea.cpp
15750x009d5964
11lyx::frontend::GuiView::addWorkAreaGuiView.cpp1152
0x009ab8be
12lyx::frontend::GuiView::setBufferGuiView.cpp1330
0x009b26aa
13lyx::frontend::GuiView::loadDocumentGuiView.cpp1819
0x009b4a93
14lyx::frontend::GuiView::openDocumentGuiView.cpp1897
0x009b7b54
15lyx::frontend::GuiApplication::dispatchGuiApplication.cpp
13300x00988b0f
16lyx::frontend::GuiApplication::dispatchGuiApplication.cpp
10960x009813b9

17lyx::dispatchLyX.cpp12280x005a2218
18lyx::frontend::Action::actionAction.cpp66
0x00a1d023
19lyx::frontend::Action::qt_metacallmoc_Action.cpp77
0x00a1d083

20QMetaObject::activateqobject.cpp32950x00313ab66606
... 




fail.lyx
Description: application/lyx


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
 The lyx2lyx part was more complicated than I thought. However, attached is
 the patch to go in.

Just one question to the lyx2lyx code: did you exclude minus at the first 
position? -2cm is a valid non-glue length that doesn't need to be reverted.

Apart from that, it looks good to me. Could you shove it in if the lyx2lyx 
issue is sorted out?

Jürgen


RE: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Vincent van Ravesteijn - TNW
 
 Attached a patch that implements the glue length
 for texted. Maybe you can do the file format/lyx2lyx
 stuff.

 The lyx2lyx part was more complicated than I thought.
 However, attached is the patch to go in.

Besides the awful duplication of code, the following looks suspicious:

sstring = value + \\paperwidth + end
^

And is this warning necessary, or a relic of the debugging phase ?
+document.warning(value_plus:  + value)


regards Uwe

Vincent


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

Vincent van Ravesteijn - TNW schrieb:


Besides the awful duplication of code,


I haven't figured out a simpler solution. But anyway, it works.


the following looks suspicious:

sstring = value + \\paperwidth + end
^


Fixed.


And is this warning necessary, or a relic of the debugging phase ?
+document.warning(value_plus:  + value)


Yes, this was a debugging relict. I removed it.

 Just one question to the lyx2lyx code: did you exclude minus at the first
 position? -2cm is a valid non-glue length that doesn't need to be reverted.

minus is never at the first position when there is also a plus. Lengths like 5col%-2text% are 
converted correctly. If you find any further problem, please report me.


 Could you shove it in if the lyx2lyx issue is sorted out?

Done.

thanks for your reviews and regards
Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
  Just one question to the lyx2lyx code: did you exclude minus at the first

   position? -2cm is a valid non-glue length that doesn't need to be
 reverted.

 minus is never at the first position when there is also a plus. Lengths
 like 5col%-2text% are converted correctly. If you find any further problem,
 please report me.

I was talking about negative *non*-glue lengths such as -2cm, which do not 
need to be reverted at all. In other words: the lyx2lyx routine that parses 
for the minus values should exclude lengths where the minus occurs only in 
position null.
Have a look at the last example in the attached test case.

Nothing in the test case, BTW, does revert correctly to 1.6.

Jürgen


testglues.lyx
Description: application/lyx


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

 I was talking about negative *non*-glue lengths such as -2cm, which do not
 need to be reverted at all.

This already works correctly.

 Nothing in the test case, BTW, does revert correctly to 1.6.

Because I only reverted when the glue lengths contain at least a percent 
length. This is now fixed.
Furthermore cases like
-2mm+3cm
and
-1mm-2cm
are now handled correctly, see the attached testcase.

regards Uwe


testglues.lyx
Description: application/lyx


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
  I was talking about negative *non*-glue lengths such as -2cm, which do
  not

   need to be reverted at all.

 This already works correctly.

Good.

   Nothing in the test case, BTW, does revert correctly to 1.6.

 Because I only reverted when the glue lengths contain at least a percent
 length. This is now fixed. Furthermore cases like
 -2mm+3cm
 and
 -1mm-2cm
 are now handled correctly, see the attached testcase.

Thanks, but the result is not correct. Lyx2lyx reverts to

\hspace*{1cm+1mm-2mm}

and

\hspace*{1cm+-1mm}


but the correct LaTeX syntax is

\hspace*{1cm plus 1mm minus 2mm}

and

\hspace*{1cm plus 1mm minus 1mm}

Look at the LaTeX output of the original file.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
BTW I think that this code

  o = document.body[i+1].find(\\length)
  if o == -1:
  document.warning(Error: Cannot find lenght for \\hspace!)
  break
  # search for the beginning of the value via the space
  k = document.body[i+1].find( )
  length = document.body[i+1][k+1:]

could be replaced by

length = get_value(document.body, '\\length', i+1)
if length == '':
document.warning(Error: Cannot find lenght for \\hspace!)
return

(adapted from revert_hspace in lyx_1_6.py).

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

 Thanks, but the result is not correct. Lyx2lyx reverts to
 \hspace*{1cm+1mm-2mm}

The bug was again that I only did the - - minus conversion only when the length contained a 
percent unit. This is now fixed.


regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
 The bug was again that I only did the - - minus conversion only when
 the length contained a percent unit. This is now fixed.

Thanks, it works now. I committed some small tweaks.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

 Thanks, it works now. I committed some small tweaks.

Thanks.

regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> The lyx2lyx part was more complicated than I thought. However, attached is
> the patch to go in.

Just one question to the lyx2lyx code: did you exclude minus at the first 
position? "-2cm" is a valid non-glue length that doesn't need to be reverted.

Apart from that, it looks good to me. Could you shove it in if the lyx2lyx 
issue is sorted out?

Jürgen


RE: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Vincent van Ravesteijn - TNW
 
>> Attached a patch that implements the glue length
>> for texted. Maybe you can do the file format/lyx2lyx
>> stuff.
>
> The lyx2lyx part was more complicated than I thought.
> However, attached is the patch to go in.

Besides the awful duplication of code, the following looks suspicious:

sstring = value + "\\paperwidth" + end
^

And is this warning necessary, or a relic of the debugging phase ?
+document.warning("value_plus: " + value)


>regards Uwe

Vincent


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

Vincent van Ravesteijn - TNW schrieb:


Besides the awful duplication of code,


I haven't figured out a simpler solution. But anyway, it works.


the following looks suspicious:

sstring = value + "\\paperwidth" + end
^


Fixed.


And is this warning necessary, or a relic of the debugging phase ?
+document.warning("value_plus: " + value)


Yes, this was a debugging relict. I removed it.

> Just one question to the lyx2lyx code: did you exclude minus at the first
> position? "-2cm" is a valid non-glue length that doesn't need to be reverted.

minus is never at the first position when there is also a plus. Lengths like 5col%-2text% are 
converted correctly. If you find any further problem, please report me.


> Could you shove it in if the lyx2lyx issue is sorted out?

Done.

thanks for your reviews and regards
Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> > Just one question to the lyx2lyx code: did you exclude minus at the first
>
>  > position? "-2cm" is a valid non-glue length that doesn't need to be
> reverted.
>
> minus is never at the first position when there is also a plus. Lengths
> like 5col%-2text% are converted correctly. If you find any further problem,
> please report me.

I was talking about negative *non*-glue lengths such as "-2cm", which do not 
need to be reverted at all. In other words: the lyx2lyx routine that parses 
for the minus values should exclude lengths where the minus occurs only in 
position null.
Have a look at the last example in the attached test case.

Nothing in the test case, BTW, does revert correctly to 1.6.

Jürgen


testglues.lyx
Description: application/lyx


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

> I was talking about negative *non*-glue lengths such as "-2cm", which do not
> need to be reverted at all.

This already works correctly.

> Nothing in the test case, BTW, does revert correctly to 1.6.

Because I only reverted when the glue lengths contain at least a percent 
length. This is now fixed.
Furthermore cases like
-2mm+3cm
and
-1mm-2cm
are now handled correctly, see the attached testcase.

regards Uwe


testglues.lyx
Description: application/lyx


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> > I was talking about negative *non*-glue lengths such as "-2cm", which do
> > not
>
>  > need to be reverted at all.
>
> This already works correctly.

Good.

>  > Nothing in the test case, BTW, does revert correctly to 1.6.
>
> Because I only reverted when the glue lengths contain at least a percent
> length. This is now fixed. Furthermore cases like
> -2mm+3cm
> and
> -1mm-2cm
> are now handled correctly, see the attached testcase.

Thanks, but the result is not correct. Lyx2lyx reverts to

\hspace*{1cm+1mm-2mm}

and

\hspace*{1cm+-1mm}


but the correct LaTeX syntax is

\hspace*{1cm plus 1mm minus 2mm}

and

\hspace*{1cm plus 1mm minus 1mm}

Look at the LaTeX output of the original file.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
BTW I think that this code

  o = document.body[i+1].find("\\length")
  if o == -1:
  document.warning("Error: Cannot find lenght for \\hspace!")
  break
  # search for the beginning of the value via the space
  k = document.body[i+1].find(" ")
  length = document.body[i+1][k+1:]

could be replaced by

length = get_value(document.body, '\\length', i+1)
if length == '':
document.warning("Error: Cannot find lenght for \\hspace!")
return

(adapted from revert_hspace in lyx_1_6.py).

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

> Thanks, but the result is not correct. Lyx2lyx reverts to
> \hspace*{1cm+1mm-2mm}

The bug was again that I only did the "-" -> "minus" conversion only when the length contained a 
percent unit. This is now fixed.


regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> The bug was again that I only did the "-" -> "minus" conversion only when
> the length contained a percent unit. This is now fixed.

Thanks, it works now. I committed some small tweaks.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-21 Thread Uwe Stöhr

> Thanks, it works now. I committed some small tweaks.

Thanks.

regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Uwe Stöhr

 Looks good.

The patch is in.

 The HSpace dialog lacks in general support for glue lengths, see
 http://www.lyx.org/trac/ticket/6099 but this is independent from support
 for percent lengths.)

 Should be easy to implement as well, while you're at it. Just replace the
 Length in InsetSpace by a GlueLength (and again increase the file format).

It is not that easy because Mathed also uses the HSpace dialog and uses routines like inPixels. 
(Glue lengths are also valid in Mathed's HSpace inset.) These routines only exist for Length but not 
for GlueLength. Moreover VSpace.cpp contains many routines to handle glue lengths in the lineEdit 
field. These are missing for GlueLengths and should be implemented to HSpace.cpp. The HSpace dialog 
should then use the HSpace class instead of the Length class.


I won't have time to work further on this the next weeks, so please take over as you are deep enough 
in this business as well as I am.


regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
 It is not that easy because Mathed also uses the HSpace dialog and uses
 routines like inPixels. (Glue lengths are also valid in Mathed's HSpace
 inset.) 
 These routines only exist for Length but not for GlueLength.

Then implement it for texted first.

 Moreover VSpace.cpp contains many routines to handle glue lengths in the
 lineEdit field. These are missing for GlueLengths and should be implemented
 to HSpace.cpp. The HSpace dialog should then use the HSpace class instead
 of the Length class.

The dialog is independent from VSpace. This is handled by the frontend itself 
(widgetsToLength and validator).

 I won't have time to work further on this the next weeks, so please take
 over as you are deep enough in this business as well as I am.

I don't have time either.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Jürgen Spitzmüller
Jürgen Spitzmüller wrote:
  I won't have time to work further on this the next weeks, so please take
  over as you are deep enough in this business as well as I am.

 I don't have time either.

I couldn't resist.
Attached a patch that implements the glue length for texted. Maybe you can do 
the file format/lyx2lyx stuff.

Jürgen
Index: src/insets/InsetSpace.cpp
===
--- src/insets/InsetSpace.cpp	(Revision 30712)
+++ src/insets/InsetSpace.cpp	(Arbeitskopie)
@@ -53,7 +53,7 @@
 }
 
 
-Length InsetSpace::length() const
+GlueLength InsetSpace::length() const
 {
 	return params_.length;
 }
@@ -130,12 +130,14 @@
 		message = _(Horizontal Fill (Down Brace));
 		break;
 	case InsetSpaceParams::CUSTOM:
+		// FIXME unicode
 		message = support::bformat(_(Horizontal Space (%1$s)),
-params_.length.asDocstring());
+from_ascii(params_.length.asString()));
 		break;
 	case InsetSpaceParams::CUSTOM_PROTECTED:
+		// FIXME unicode
 		message = support::bformat(_(Protected Horizontal Space (%1$s)),
-params_.length.asDocstring());
+from_ascii(params_.length.asString()));
 		break;
 	}
 	return message;
@@ -238,7 +240,7 @@
 		case InsetSpaceParams::CUSTOM:
 		case InsetSpaceParams::CUSTOM_PROTECTED: {
 			int const w = 
-params_.length.inPixels(mi.base.textwidth,
+params_.length.len().inPixels(mi.base.textwidth,
 			fm.width(char_type('M')));
 			int const minw = (w  0) ? 3 * arrow_size : 4;
 			dim.wid = max(minw, abs(w));
@@ -264,7 +266,7 @@
 {
 	Dimension const dim = dimension(*pi.base.bv);
 
-	if (isStretchableSpace() || params_.length.value()  0) {
+	if (isStretchableSpace() || params_.length.len().value()  0) {
 		int const asc = theFontMetrics(pi.base.font).ascent('M');
 		int const desc = theFontMetrics(pi.base.font).descent('M');
 		// Pixel height divisible by 2 for prettier fill graphics:
@@ -450,7 +452,7 @@
 		break;
 	}
 	
-	if (!length.empty())
+	if (!length.len().empty())
 		os  \n\\length   length.asString();
 }
 
Index: src/insets/InsetSpace.h
===
--- src/insets/InsetSpace.h	(Revision 30712)
+++ src/insets/InsetSpace.h	(Arbeitskopie)
@@ -81,7 +81,7 @@
 	///
 	Kind kind;
 	///
-	Length length;
+	GlueLength length;
 	/**
 	 * Whether these params are to be used in mathed.
 	 * This determines the set of valid kinds.
@@ -110,7 +110,7 @@
 	///
 	static std::string params2string(InsetSpaceParams const );
 	///
-	Length length() const;
+	GlueLength length() const;
 
 	///
 	docstring toolTip(BufferView const  bv, int x, int y) const;
Index: src/mathed/InsetMathSpace.cpp
===
--- src/mathed/InsetMathSpace.cpp	(Revision 30712)
+++ src/mathed/InsetMathSpace.cpp	(Arbeitskopie)
@@ -214,7 +214,7 @@
 	LASSERT(space_info[space_].visible, /**/);
 	InsetSpaceParams isp(true);
 	isp.kind = space_info[space_].kind;
-	isp.length = length_;
+	isp.length = GlueLength(length_);
 	return InsetSpace::params2string(isp);
 }
 
Index: src/frontends/qt4/GuiHSpace.cpp
===
--- src/frontends/qt4/GuiHSpace.cpp	(Revision 30712)
+++ src/frontends/qt4/GuiHSpace.cpp	(Arbeitskopie)
@@ -57,7 +57,10 @@
 	connect(fillPatternCO, SIGNAL(activated(int)),
 		this, SLOT(patternChanged()));
 
-	valueLE-setValidator(unsignedLengthValidator(valueLE));
+	if (params_.math)
+		valueLE-setValidator(unsignedLengthValidator(valueLE));
+	else
+		valueLE-setValidator(unsignedGlueLengthValidator(valueLE));
 
 	// Manage the ok, apply, restore and cancel/close buttons
 	bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
@@ -245,9 +248,10 @@
 	keep-setChecked(protect);
 
 	Length::UNIT const default_unit = Length::defaultUnit();
-	if (item == (params.math ? 9 : 7))
-		lengthToWidgets(value, unit, params.length, default_unit);
-	else
+	if (item == (params.math ? 9 : 7)) {
+		string length = params.length.asString();
+		lengthToWidgets(value, unit, length, default_unit);
+	} else
 		lengthToWidgets(value, unit, , default_unit);
 }
 
@@ -269,7 +273,7 @@
 		case 8: params.kind = InsetSpaceParams::QQUAD; break;
 		case 9:
 			params.kind = InsetSpaceParams::CUSTOM;
-			params.length = Length(widgetsToLength(value, unit));
+			params.length = GlueLength(widgetsToLength(value, unit));
 			break;
 		}
 		return params;
@@ -323,7 +327,7 @@
 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
 			else
 params.kind = InsetSpaceParams::CUSTOM;
-			params.length = Length(widgetsToLength(value, unit));
+			params.length = GlueLength(widgetsToLength(value, unit));
 			break;
 	}
 	return params;
Index: src/factory.cpp
===
--- src/factory.cpp	(Revision 30712)
+++ src/factory.cpp	(Arbeitskopie)
@@ -387,22 +387,22 @@
 			else if (name == hrulefill)
 isp.kind = InsetSpaceParams::HRULEFILL;
 			else if (name == hspace) {
-

Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Uwe Stöhr
 = str(float(value)/100)
-return True, + value + \\paperheight
+minus = string.rfind(-, 0, i)
+plus = string.rfind(+, 0, i)
+if plus == -1 and minus == -1:
+value = string[:i]
+value = str(float(value)/100)
+end = string[i+8:]
+string = value + \\paperheight + end
+if plus  minus:
+value = string[plus+1:i]
+document.warning(value_plus:  + value)
+value = str(float(value)/100)
+begin = string[:plus+1]
+end = string[i+8:]
+string = begin + value + \\paperheight + end
+if plus  minus:
+value = string[minus+1:i]
+value = str(float(value)/100)
+begin = string[:minus+1]
+string = begin + value + \\paperheight
 if percent ==  False:
-return False, +  string
+return False, + string
+else:
+string = string.replace(+,  plus )
+string = string.replace(-,  minus )
+return True, + string
+
 
-
 
 
 
@@ -945,6 +1040,53 @@
   j = i
 
 
+def revert_hspace_glue_lengths(document):
+ Revert HSpace glue lengths to ERT 
+i = 0
+j = 0
+while True:
+  i = find_token(document.body, \\begin_inset space \hspace{}, i)
+  if i == -1:
+  j = find_token(document.body, \\begin_inset space \hspace*{}, j)
+  if j == -1:
+  break
+  else:
+  star = True
+  i = j
+  else:
+  star = False
+  # only revert when a custom length was set and when
+  # it used a percent length
+  o = document.body[i+1].find(\\length)
+  if o == -1:
+  document.warning(Error: Cannot find lenght for \\hspace!)
+  break
+  # search for the beginning of the value via the space
+  k = document.body[i+1].find( )
+  length = document.body[i+1][k+1:]
+  # check if the length contains a plus or minus
+  l = length.find(+)
+  if l == -1:
+  l = length.find(-)
+  if l == -1:
+  break
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns bool,length
+  m = length.find(,)
+  percent = length[:m]
+  length = length[m+1:]
+  # revert the HSpace inset to ERT
+  if percent == True:
+  if star == True:
+  subst = [put_cmd_in_ert(\\hspace*{ + length + })]
+  else:
+  subst = [put_cmd_in_ert(\\hspace{ + length + })]
+  document.body[i:i+3] = subst
+  i = i + 2
+  j = i
+
+
 ##
 # Conversion hub
 #
@@ -971,10 +1113,12 @@
[364, []],
[365, []],
[366, []],
-   [367, []]
+   [367, []],
+   [368, []]
   ]
 
-revert =  [[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
+revert =  [[367, [revert_hspace_glue_lengths]],
+   [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
[365, [revert_percent_skip_lengths]],
[364, [revert_paragraph_indentation]],
[363, [revert_branch_filename]],
Index: src/Buffer.cpp
===
--- src/Buffer.cpp	(revision 30715)
+++ src/Buffer.cpp	(working copy)
@@ -127,7 +127,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 367; // uwestoehr: percent lengths for the VSpace dialog
+int const LYX_FORMAT = 368; // spitz, uwestoehr: glue lengths for the HSpace dialog
 
 typedef mapstring, bool DepClean;
 typedef mapdocstring, pairInsetLabel const *, Buffer::References  RefCache;
Index: src/factory.cpp
===
--- src/factory.cpp	(revision 30715)
+++ src/factory.cpp	(working copy)
@@ -387,22 +387,22 @@
 			else if (name == hrulefill)
 isp.kind = InsetSpaceParams::HRULEFILL;
 			else if (name == hspace) {
-if (len.empty() || !isValidLength(len)) {
+if (len.empty() || !isValidGlueLength(len)) {
 	lyxerr  LyX function 'space-insert hspace' 
 	needs a valid length argument.  endl;
 	break;
 }
 isp.kind = InsetSpaceParams::CUSTOM;
-isp.length = Length(len);
+isp.length = GlueLength(len);
 			}
 			else if (name == hspace*) {
-if (len.empty() || !isValidLength(len)) {
+if (len.empty() || !isValidGlueLength(len)) {
 	lyxerr  LyX function 'space-insert hspace*' 
 	needs a valid length argument.  endl;
 	break;
 }
 isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
-isp.length = Length(len);
+isp.length = GlueLength(len);
 			}
 			else {
 lyxerr  Wrong argument for LyX function 'space-insert'.  endl;
Index: src/frontends/qt4/GuiHSpace.cpp

Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Uwe Stöhr

> Looks good.

The patch is in.

>> The HSpace dialog lacks in general support for glue lengths, see
>> http://www.lyx.org/trac/ticket/6099 but this is independent from support
>> for percent lengths.)
>
> Should be easy to implement as well, while you're at it. Just replace the
> Length in InsetSpace by a GlueLength (and again increase the file format).

It is not that easy because Mathed also uses the HSpace dialog and uses routines like "inPixels". 
(Glue lengths are also valid in Mathed's HSpace inset.) These routines only exist for Length but not 
for GlueLength. Moreover VSpace.cpp contains many routines to handle glue lengths in the lineEdit 
field. These are missing for GlueLengths and should be implemented to HSpace.cpp. The HSpace dialog 
should then use the HSpace class instead of the Length class.


I won't have time to work further on this the next weeks, so please take over as you are deep enough 
in this business as well as I am.


regards Uwe


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> It is not that easy because Mathed also uses the HSpace dialog and uses
> routines like "inPixels". (Glue lengths are also valid in Mathed's HSpace
> inset.) 
> These routines only exist for Length but not for GlueLength.

Then implement it for texted first.

> Moreover VSpace.cpp contains many routines to handle glue lengths in the
> lineEdit field. These are missing for GlueLengths and should be implemented
> to HSpace.cpp. The HSpace dialog should then use the HSpace class instead
> of the Length class.

The dialog is independent from VSpace. This is handled by the frontend itself 
(widgetsToLength and validator).

> I won't have time to work further on this the next weeks, so please take
> over as you are deep enough in this business as well as I am.

I don't have time either.

Jürgen


Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Jürgen Spitzmüller
Jürgen Spitzmüller wrote:
> > I won't have time to work further on this the next weeks, so please take
> > over as you are deep enough in this business as well as I am.
>
> I don't have time either.

I couldn't resist.
Attached a patch that implements the glue length for texted. Maybe you can do 
the file format/lyx2lyx stuff.

Jürgen
Index: src/insets/InsetSpace.cpp
===
--- src/insets/InsetSpace.cpp	(Revision 30712)
+++ src/insets/InsetSpace.cpp	(Arbeitskopie)
@@ -53,7 +53,7 @@
 }
 
 
-Length InsetSpace::length() const
+GlueLength InsetSpace::length() const
 {
 	return params_.length;
 }
@@ -130,12 +130,14 @@
 		message = _("Horizontal Fill (Down Brace)");
 		break;
 	case InsetSpaceParams::CUSTOM:
+		// FIXME unicode
 		message = support::bformat(_("Horizontal Space (%1$s)"),
-params_.length.asDocstring());
+from_ascii(params_.length.asString()));
 		break;
 	case InsetSpaceParams::CUSTOM_PROTECTED:
+		// FIXME unicode
 		message = support::bformat(_("Protected Horizontal Space (%1$s)"),
-params_.length.asDocstring());
+from_ascii(params_.length.asString()));
 		break;
 	}
 	return message;
@@ -238,7 +240,7 @@
 		case InsetSpaceParams::CUSTOM:
 		case InsetSpaceParams::CUSTOM_PROTECTED: {
 			int const w = 
-params_.length.inPixels(mi.base.textwidth,
+params_.length.len().inPixels(mi.base.textwidth,
 			fm.width(char_type('M')));
 			int const minw = (w < 0) ? 3 * arrow_size : 4;
 			dim.wid = max(minw, abs(w));
@@ -264,7 +266,7 @@
 {
 	Dimension const dim = dimension(*pi.base.bv);
 
-	if (isStretchableSpace() || params_.length.value() < 0) {
+	if (isStretchableSpace() || params_.length.len().value() < 0) {
 		int const asc = theFontMetrics(pi.base.font).ascent('M');
 		int const desc = theFontMetrics(pi.base.font).descent('M');
 		// Pixel height divisible by 2 for prettier fill graphics:
@@ -450,7 +452,7 @@
 		break;
 	}
 	
-	if (!length.empty())
+	if (!length.len().empty())
 		os << "\n\\length " << length.asString();
 }
 
Index: src/insets/InsetSpace.h
===
--- src/insets/InsetSpace.h	(Revision 30712)
+++ src/insets/InsetSpace.h	(Arbeitskopie)
@@ -81,7 +81,7 @@
 	///
 	Kind kind;
 	///
-	Length length;
+	GlueLength length;
 	/**
 	 * Whether these params are to be used in mathed.
 	 * This determines the set of valid kinds.
@@ -110,7 +110,7 @@
 	///
 	static std::string params2string(InsetSpaceParams const &);
 	///
-	Length length() const;
+	GlueLength length() const;
 
 	///
 	docstring toolTip(BufferView const & bv, int x, int y) const;
Index: src/mathed/InsetMathSpace.cpp
===
--- src/mathed/InsetMathSpace.cpp	(Revision 30712)
+++ src/mathed/InsetMathSpace.cpp	(Arbeitskopie)
@@ -214,7 +214,7 @@
 	LASSERT(space_info[space_].visible, /**/);
 	InsetSpaceParams isp(true);
 	isp.kind = space_info[space_].kind;
-	isp.length = length_;
+	isp.length = GlueLength(length_);
 	return InsetSpace::params2string(isp);
 }
 
Index: src/frontends/qt4/GuiHSpace.cpp
===
--- src/frontends/qt4/GuiHSpace.cpp	(Revision 30712)
+++ src/frontends/qt4/GuiHSpace.cpp	(Arbeitskopie)
@@ -57,7 +57,10 @@
 	connect(fillPatternCO, SIGNAL(activated(int)),
 		this, SLOT(patternChanged()));
 
-	valueLE->setValidator(unsignedLengthValidator(valueLE));
+	if (params_.math)
+		valueLE->setValidator(unsignedLengthValidator(valueLE));
+	else
+		valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
 
 	// Manage the ok, apply, restore and cancel/close buttons
 	bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
@@ -245,9 +248,10 @@
 	keep->setChecked(protect);
 
 	Length::UNIT const default_unit = Length::defaultUnit();
-	if (item == (params.math ? 9 : 7))
-		lengthToWidgets(value, unit, params.length, default_unit);
-	else
+	if (item == (params.math ? 9 : 7)) {
+		string length = params.length.asString();
+		lengthToWidgets(value, unit, length, default_unit);
+	} else
 		lengthToWidgets(value, unit, "", default_unit);
 }
 
@@ -269,7 +273,7 @@
 		case 8: params.kind = InsetSpaceParams::QQUAD; break;
 		case 9:
 			params.kind = InsetSpaceParams::CUSTOM;
-			params.length = Length(widgetsToLength(value, unit));
+			params.length = GlueLength(widgetsToLength(value, unit));
 			break;
 		}
 		return params;
@@ -323,7 +327,7 @@
 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
 			else
 params.kind = InsetSpaceParams::CUSTOM;
-			params.length = Length(widgetsToLength(value, unit));
+			params.length = GlueLength(widgetsToLength(value, unit));
 			break;
 	}
 	return params;
Index: src/factory.cpp
===
--- src/factory.cpp	(Revision 30712)
+++ src/factory.cpp	(Arbeitskopie)
@@ -387,22 +387,22 @@
 			else if (name == "hrulefill")
 isp.kind = InsetSpaceParams::HRULEFILL;
 			

Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-20 Thread Uwe Stöhr
plus > minus:
+value = string[plus+1:i]
+value = str(float(value)/100)
+begin = string[:plus+1]
+end = string[i+8:]
+string = begin + value + "\\textheight" + end
+if plus < minus:
+value = string[minus+1:i]
+value = str(float(value)/100)
+begin = string[:minus+1]
+string = begin + value + "\\textheight"
 i = string.find("pheight%")
 if i > -1:
 percent = True
-value = string[:i]
-value = str(float(value)/100)
-return "True," + value + "\\paperheight"
+minus = string.rfind("-", 0, i)
+plus = string.rfind("+", 0, i)
+if plus == -1 and minus == -1:
+value = string[:i]
+value = str(float(value)/100)
+end = string[i+8:]
+string = value + "\\paperheight" + end
+if plus > minus:
+value = string[plus+1:i]
+document.warning("value_plus: " + value)
+value = str(float(value)/100)
+begin = string[:plus+1]
+end = string[i+8:]
+string = begin + value + "\\paperheight" + end
+if plus < minus:
+value = string[minus+1:i]
+value = str(float(value)/100)
+begin = string[:minus+1]
+string = begin + value + "\\paperheight"
 if percent ==  False:
-return "False," +  string
+return "False," + string
+else:
+string = string.replace("+", " plus ")
+string = string.replace("-", " minus ")
+return "True," + string
+
 
-
 
 
 
@@ -945,6 +1040,53 @@
   j = i
 
 
+def revert_hspace_glue_lengths(document):
+" Revert HSpace glue lengths to ERT "
+i = 0
+j = 0
+while True:
+  i = find_token(document.body, "\\begin_inset space \hspace{}", i)
+  if i == -1:
+  j = find_token(document.body, "\\begin_inset space \hspace*{}", j)
+  if j == -1:
+  break
+  else:
+  star = True
+  i = j
+  else:
+  star = False
+  # only revert when a custom length was set and when
+  # it used a percent length
+  o = document.body[i+1].find("\\length")
+  if o == -1:
+  document.warning("Error: Cannot find lenght for \\hspace!")
+  break
+  # search for the beginning of the value via the space
+  k = document.body[i+1].find(" ")
+  length = document.body[i+1][k+1:]
+  # check if the length contains a plus or minus
+  l = length.find("+")
+  if l == -1:
+  l = length.find("-")
+  if l == -1:
+  break
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns "bool,length"
+  m = length.find(",")
+  percent = length[:m]
+  length = length[m+1:]
+  # revert the HSpace inset to ERT
+  if percent == "True":
+  if star == True:
+  subst = [put_cmd_in_ert("\\hspace*{" + length + "}")]
+  else:
+  subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
+  document.body[i:i+3] = subst
+  i = i + 2
+  j = i
+
+
 ##
 # Conversion hub
 #
@@ -971,10 +1113,12 @@
[364, []],
[365, []],
[366, []],
-   [367, []]
+   [367, []],
+   [368, []]
   ]
 
-revert =  [[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
+revert =  [[367, [revert_hspace_glue_lengths]],
+   [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
[365, [revert_percent_skip_lengths]],
[364, [revert_paragraph_indentation]],
[363, [revert_branch_filename]],
Index: src/Buffer.cpp
===
--- src/Buffer.cpp	(revision 30715)
+++ src/Buffer.cpp	(working copy)
@@ -127,7 +127,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 367; // uwestoehr: percent lengths for the VSpace dialog
+int const LYX_FORMAT = 368; // spitz, uwestoehr: glue lengths for the HSpace dialog
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair > RefCache;
Index: src/factory.cpp
===
--- src/factory.cpp	(revision 30715)
+++ src/factory.cpp	(working copy)
@@ -387,22 +387,22 @@
 			else if (name == "hrulefill")
 isp.kind = InsetSpaceParams::HRULEFILL;
 		

[patch] allow percent lengths for VSpace and HSpace dialog

2009-07-19 Thread Uwe Stöhr

The attached simple patch allows to use percent lengths in the HSpace and 
VSpace dialog.
(In the VSpace dialog you can with this patch also insert things like this:
5col%+-1mm
The HSpace dialog lacks in general support for glue lengths, see http://www.lyx.org/trac/ticket/6099 
but this is independent from support for percent lengths.)


OK?

regards Uwe

Index: development/FORMAT
===
--- development/FORMAT	(revision 30696)
+++ development/FORMAT	(working copy)
@@ -2,6 +2,10 @@
 ---
 
 2009-07-20 Uwe Stöhr uwesto...@web.de
+	* Format incremented to 367: allow to use percent lengths for
+	  vertical and horizontal spaces.
+
+2009-07-20 Uwe Stöhr uwesto...@web.de
 	* Format incremented to 366: allow to use percent lengths for the
 	  paragraph skip separation.
 
Index: lib/lyx2lyx/lyx_2_0.py
===
--- lib/lyx2lyx/lyx_2_0.py	(revision 30697)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -93,7 +93,7 @@
 for rep in unicode_reps:
 string = string.replace(rep[1], rep[0].replace('', '\\'))
 string = string.replace('\\', \\backslash\n)
-string = \\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n \
+string = \\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n \
   + string + \n\\end_layout\n\\end_inset
 return string
 
@@ -864,6 +864,87 @@
   i = i + 1
 
 
+def revert_percent_vspace_lengths(document):
+ Revert relative VSpace lengths to ERT 
+i = 0
+while True:
+  i = find_token(document.body, \\begin_inset VSpace, i)
+  if i == -1:
+  break
+  # only revert when a custom length was set and when
+  # it used a percent length
+  j = document.body[i].find(defskip)
+  k = document.body[i].find(smallskip)
+  l = document.body[i].find(medskip)
+  m = document.body[i].find(bigskip)
+  n = document.body[i].find(vfill)
+  if (j  -1) or (k  -1) or (l  -1) or (m  -1) or (n  -1):
+  break
+  else:
+  # search for the beginning of the value via the last space
+  o = document.body[i].rfind( )
+  length = document.body[i][o+1:]
+  # check if the space has a star (protected space)
+  p = document.body[i].rfind(*)
+  if p  -1:
+  length = length[:-1]
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns bool,length
+  q = length.find(,)
+  percent = length[:q]
+  length = length[q+1:]
+  # revert the VSpace inset to ERT
+  if percent == True:
+  if p  -1:
+  subst = [put_cmd_in_ert(\\vspace*{ + length + })]
+  else:
+  subst = [put_cmd_in_ert(\\vspace{ + length + })]
+  document.body[i:i+2] = subst
+  i = i + 1
+
+
+def revert_percent_hspace_lengths(document):
+ Revert relative HSpace lengths to ERT 
+i = 0
+j = 0
+while True:
+  i = find_token(document.body, \\begin_inset space \hspace{}, i)
+  if i == -1:
+  j = find_token(document.body, \\begin_inset space \hspace*{}, j)
+  if j == -1:
+  break
+  else:
+  star = True
+  i = j
+  else:
+  star = False
+  # only revert when a custom length was set and when
+  # it used a percent length
+  o = document.body[i+1].find(\\length)
+  if o == -1:
+  document.warning(Error: Cannot find lenght for \\hspace!)
+  break
+  # search for the beginning of the value via the space
+  k = document.body[i+1].find( )
+  length = document.body[i+1][k+1:]
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns bool,length
+  m = length.find(,)
+  percent = length[:m]
+  length = length[m+1:]
+  # revert the HSpace inset to ERT
+  if percent == True:
+  if star == True:
+  subst = [put_cmd_in_ert(\\hspace*{ + length + })]
+  else:
+  subst = [put_cmd_in_ert(\\hspace{ + length + })]
+  document.body[i:i+3] = subst
+  i = i + 2
+  j = i
+
+
 ##
 # Conversion hub
 #
@@ -889,10 +970,12 @@
[363, []],
[364, []],
[365, []],
-   [366, []]
+   [366, []],
+   [367, []]
   ]
 
-revert =  [[365, [revert_percent_skip_lengths]],
+revert =  [[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
+   [365, [revert_percent_skip_lengths]],
[364, [revert_paragraph_indentation]],
[363, [revert_branch_filename]],
[362, [revert_longtable_align]],
Index: src/Buffer.cpp
===
--- src/Buffer.cpp	(revision 30696)
+++ src/Buffer.cpp	(working copy)
@@ -127,7 +127,7 @@
 
 // Do

Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-19 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
 The attached simple patch allows to use percent lengths in the HSpace and
 VSpace dialog. (In the VSpace dialog you can with this patch also insert
 things like this: 5col%+-1mm

Looks good.

 The HSpace dialog lacks in general support for glue lengths, see
 http://www.lyx.org/trac/ticket/6099 but this is independent from support
 for percent lengths.)

Should be easy to implement as well, while you're at it. Just replace the 
Length in InsetSpace by a GlueLength (and again increase the file format).

Jürgen


[patch] allow percent lengths for VSpace and HSpace dialog

2009-07-19 Thread Uwe Stöhr

The attached simple patch allows to use percent lengths in the HSpace and 
VSpace dialog.
(In the VSpace dialog you can with this patch also insert things like this:
5col%+-1mm
The HSpace dialog lacks in general support for glue lengths, see http://www.lyx.org/trac/ticket/6099 
but this is independent from support for percent lengths.)


OK?

regards Uwe

Index: development/FORMAT
===
--- development/FORMAT	(revision 30696)
+++ development/FORMAT	(working copy)
@@ -2,6 +2,10 @@
 ---
 
 2009-07-20 Uwe Stöhr <uwesto...@web.de>
+	* Format incremented to 367: allow to use percent lengths for
+	  vertical and horizontal spaces.
+
+2009-07-20 Uwe Stöhr <uwesto...@web.de>
 	* Format incremented to 366: allow to use percent lengths for the
 	  paragraph skip separation.
 
Index: lib/lyx2lyx/lyx_2_0.py
===
--- lib/lyx2lyx/lyx_2_0.py	(revision 30697)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -93,7 +93,7 @@
 for rep in unicode_reps:
 string = string.replace(rep[1], rep[0].replace('', '\\'))
 string = string.replace('\\', "\\backslash\n")
-string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n" \
+string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
   + string + "\n\\end_layout\n\\end_inset"
 return string
 
@@ -864,6 +864,87 @@
   i = i + 1
 
 
+def revert_percent_vspace_lengths(document):
+" Revert relative VSpace lengths to ERT "
+i = 0
+while True:
+  i = find_token(document.body, "\\begin_inset VSpace", i)
+  if i == -1:
+  break
+  # only revert when a custom length was set and when
+  # it used a percent length
+  j = document.body[i].find("defskip")
+  k = document.body[i].find("smallskip")
+  l = document.body[i].find("medskip")
+  m = document.body[i].find("bigskip")
+  n = document.body[i].find("vfill")
+  if (j > -1) or (k > -1) or (l > -1) or (m > -1) or (n > -1):
+  break
+  else:
+  # search for the beginning of the value via the last space
+  o = document.body[i].rfind(" ")
+  length = document.body[i][o+1:]
+  # check if the space has a star (protected space)
+  p = document.body[i].rfind("*")
+  if p > -1:
+  length = length[:-1]
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns "bool,length"
+  q = length.find(",")
+  percent = length[:q]
+      length = length[q+1:]
+  # revert the VSpace inset to ERT
+  if percent == "True":
+  if p > -1:
+  subst = [put_cmd_in_ert("\\vspace*{" + length + "}")]
+  else:
+  subst = [put_cmd_in_ert("\\vspace{" + length + "}")]
+  document.body[i:i+2] = subst
+  i = i + 1
+
+
+def revert_percent_hspace_lengths(document):
+" Revert relative HSpace lengths to ERT "
+i = 0
+j = 0
+while True:
+  i = find_token(document.body, "\\begin_inset space \hspace{}", i)
+  if i == -1:
+  j = find_token(document.body, "\\begin_inset space \hspace*{}", j)
+  if j == -1:
+  break
+  else:
+  star = True
+  i = j
+  else:
+  star = False
+  # only revert when a custom length was set and when
+  # it used a percent length
+  o = document.body[i+1].find("\\length")
+  if o == -1:
+  document.warning("Error: Cannot find lenght for \\hspace!")
+  break
+  # search for the beginning of the value via the space
+  k = document.body[i+1].find(" ")
+  length = document.body[i+1][k+1:]
+  # handle percent lengths
+  length = latex_length(length)
+  # latex_length returns "bool,length"
+  m = length.find(",")
+  percent = length[:m]
+  length = length[m+1:]
+  # revert the HSpace inset to ERT
+  if percent == "True":
+  if star == True:
+  subst = [put_cmd_in_ert("\\hspace*{" + length + "}")]
+  else:
+  subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
+  document.body[i:i+3] = subst
+  i = i + 2
+  j = i
+
+
 ##
 # Conversion hub
 #
@@ -889,10 +970,12 @@
[363, []],
[364, []],
[365, []],
-   [366, []]
+   [366, []],
+   [367, []]
   ]
 
-revert =  [[365, [revert_percent_skip_lengths]],
+revert =  [[366, [

Re: [patch] allow percent lengths for VSpace and HSpace dialog

2009-07-19 Thread Jürgen Spitzmüller
Uwe Stöhr wrote:
> The attached simple patch allows to use percent lengths in the HSpace and
> VSpace dialog. (In the VSpace dialog you can with this patch also insert
> things like this: 5col%+-1mm

Looks good.

> The HSpace dialog lacks in general support for glue lengths, see
> http://www.lyx.org/trac/ticket/6099 but this is independent from support
> for percent lengths.)

Should be easy to implement as well, while you're at it. Just replace the 
Length in InsetSpace by a GlueLength (and again increase the file format).

Jürgen


Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-05 Thread Lars Gullik Bjønnes
Abdelrazak Younes [EMAIL PROTECTED] writes:

| Lars Gullik Bjønnes wrote:
|  Bernhard Roider [EMAIL PROTECTED] writes:
|  | Hello Lars,
|  | | as Abdel suggested i would like to ask you for SVN commit
|  access, to
|  | be able to commit my contributions by myself.
|  I am a bit reluctant, especially since (pardon me if wrong) you
|  havent
|  contributed much yet, and I have not seen/reviewed any of your
|  patches.
| 
| Please check the archive. Bernhard has fixed many bugs already and we
| (Bo, Georg, Peter and Myself) have reviewed all of his former patch.

Please indulge me and do it for yet a little while.
 
-- 
Lgb



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-05 Thread Lars Gullik Bjønnes
Abdelrazak Younes <[EMAIL PROTECTED]> writes:

| Lars Gullik Bjønnes wrote:
| > Bernhard Roider <[EMAIL PROTECTED]> writes:
| > | Hello Lars,
| > | | as Abdel suggested i would like to ask you for SVN commit
| > access, to
| > | be able to commit my contributions by myself.
| > I am a bit reluctant, especially since (pardon me if wrong) you
| > havent
| > contributed much yet, and I have not seen/reviewed any of your
| > patches.
| 
| Please check the archive. Bernhard has fixed many bugs already and we
| (Bo, Georg, Peter and Myself) have reviewed all of his former patch.

Please indulge me and do it for yet a little while.
 
-- 
Lgb



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-04 Thread Georg Baum
Am Freitag, 2. März 2007 23:40 schrieb Bernhard Roider:

 The rule for using the lexer:
 
 if you want to know if the lexer still has data to read (either from the 
stream or from the pushed 
 token) then use lex.isOK().
 If you want to test if the last reading operation was successful then use 
eg. if (lex) {...} or 
 unsuccessful then use eg. if (!lex) {...}

If these rules are correct then the whole changeset 
http://www.lyx.org/trac/changeset/17284 (including the ERT fix) is wrong, 
so the ERT bug needs to be fixed differently.


Georg



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-04 Thread Bernhard Roider

Georg Baum wrote:

Am Freitag, 2. März 2007 23:40 schrieb Bernhard Roider:


The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed 

token) then use lex.isOK().
If you want to test if the last reading operation was successful then use 
eg. if (lex) {...} or 

unsuccessful then use eg. if (!lex) {...}


If these rules are correct then the whole changeset 
http://www.lyx.org/trac/changeset/17284 (including the ERT fix) is wrong, 
so the ERT bug needs to be fixed differently.




The rules are correct after this patch is applied. For the current trunk i saw no possibility to 
test whether a read operation from the lexer was successful.


Bernhard



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-04 Thread Bernhard Roider
)
+   return;
if (token == use_parbox) {
lex.next();
use_parbox = lex.getInteger();
@@ -595,10 +600,11 @@
lyxerr  InsetBox::Read: Missing 'use_parbox'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == width) {
lex.next();
width = LyXLength(lex.getString());
@@ -606,10 +612,11 @@
lyxerr  InsetBox::Read: Missing 'width'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == special) {
lex.next();
special = lex.getString();
@@ -617,10 +624,11 @@
lyxerr  InsetBox::Read: Missing 'special'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == height) {
lex.next();
height = LyXLength(lex.getString());
@@ -628,10 +636,11 @@
lyxerr  InsetBox::Read: Missing 'height'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == height_special) {
lex.next();
height_special = lex.getString();
Index: src/insets/insetert.C
===
--- src/insets/insetert.C   (revision 17394)
+++ src/insets/insetert.C   (working copy)
@@ -466,7 +466,7 @@
 
int s;
lex  s;
-   if (lex.isOK())
+   if (lex)
status = static_castInsetCollapsable::CollapseStatus(s);
 }
 
Index: src/insets/insetnote.C
===
--- src/insets/insetnote.C  (revision 17394)
+++ src/insets/insetnote.C  (working copy)
@@ -105,7 +105,7 @@
 {
string label;
lex  label;
-   if (lex.isOK())
+   if (lex)
type = notetranslator().find(label);
 }
 
Index: src/insets/insettabular.C
===
--- src/insets/insettabular.C   (revision 17394)
+++ src/insets/insettabular.C   (working copy)
@@ -230,11 +230,11 @@
 
lex.next();
string token = lex.getString();
-   while (lex.isOK()  (token != \\end_inset)) {
+   while (lex  token != \\end_inset) {
lex.next();
token = lex.getString();
}
-   if (token != \\end_inset) {
+   if (!lex) {
lex.printError(Missing \\end_inset at this point. 
   Read: `$$Token');
}
Index: src/insets/insetvspace.C
===
--- src/insets/insetvspace.C(revision 17394)
+++ src/insets/insetvspace.C(working copy)
@@ -88,7 +88,7 @@
BOOST_ASSERT(lex.isOK());
string vsp;
lex  vsp;
-   if (lex.isOK())
+   if (lex)
space_ = VSpace(vsp);
 
string end_token;
@@ -257,7 +257,7 @@
 
string vsp;
lex  vsp;
-   if (lex.isOK())
+   if (lex)
vspace = VSpace(vsp);
 }
 
Index: src/lyxlex.C
===
--- src/lyxlex.C(revision 17394)
+++ src/lyxlex.C(working copy)
@@ -53,7 +53,7 @@
 
 bool LyXLex::isOK() const
 {
-   return pimpl_-is.good();
+   return pimpl_-inputAvailable();
 }
 
 
@@ -124,8 +124,16 @@
 
 int LyXLex::getInteger() const
 {
+   lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_-printError(integer token missing);
+   return -1;
+   }
+
if (isStrInt(pimpl_-getString()))
return convertint(pimpl_-getString());
+
+   lastReadOk_ = false;
pimpl_-printError(Bad integer `$$Token');
return -1;
 }
@@ -136,9 +144,17 @@
// replace comma with dot in case the file was written with
// the wrong locale (should be rare, but is easy enough to
// avoid).
+   lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_-printError(float token missing);
+   return -1;
+   }
+
string const str = subst(pimpl_-getString(), ,, .);
if (isStrDbl(str))
return convertdouble(str);
+
+   lastReadOk_ = false;
pimpl_-printError(Bad float `$$Token');
return -1;
 }
@@ -146,13 +162,23 @@
 
 string

Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-04 Thread Abdelrazak Younes

Lars Gullik Bjønnes wrote:

Bernhard Roider [EMAIL PROTECTED] writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to

| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.


Please check the archive. Bernhard has fixed many bugs already and we 
(Bo, Georg, Peter and Myself) have reviewed all of his former patch.




I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.


He has more than proved himself IMHO.



In the meantime we should all help with reviewing your patches and do
the commit for you.


Of course that's what we have done for the last month or two...

Abdel.


If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.





Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-04 Thread Georg Baum
Am Freitag, 2. März 2007 23:40 schrieb Bernhard Roider:

> The rule for using the lexer:
> 
> if you want to know if the lexer still has data to read (either from the 
stream or from the pushed 
> token) then use "lex.isOK()".
> If you want to test if the last reading operation was successful then use 
eg. "if (lex) {...}" or 
> unsuccessful then use eg. "if (!lex) {...}"

If these rules are correct then the whole changeset 
http://www.lyx.org/trac/changeset/17284 (including the ERT fix) is wrong, 
so the ERT bug needs to be fixed differently.


Georg



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-04 Thread Bernhard Roider

Georg Baum wrote:

Am Freitag, 2. März 2007 23:40 schrieb Bernhard Roider:


The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed 

token) then use "lex.isOK()".
If you want to test if the last reading operation was successful then use 
eg. "if (lex) {...}" or 

unsuccessful then use eg. "if (!lex) {...}"


If these rules are correct then the whole changeset 
http://www.lyx.org/trac/changeset/17284 (including the ERT fix) is wrong, 
so the ERT bug needs to be fixed differently.




The rules are correct after this patch is applied. For the current trunk i saw no possibility to 
test whether a read operation from the lexer was successful.


Bernhard



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-04 Thread Bernhard Roider
  << token << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "use_parbox") {
lex.next();
use_parbox = lex.getInteger();
@@ -595,10 +600,11 @@
lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "width") {
lex.next();
width = LyXLength(lex.getString());
@@ -606,10 +612,11 @@
lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "special") {
lex.next();
special = lex.getString();
@@ -617,10 +624,11 @@
lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "height") {
lex.next();
height = LyXLength(lex.getString());
@@ -628,10 +636,11 @@
lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "height_special") {
lex.next();
height_special = lex.getString();
Index: src/insets/insetert.C
===
--- src/insets/insetert.C   (revision 17394)
+++ src/insets/insetert.C   (working copy)
@@ -466,7 +466,7 @@
 
int s;
lex >> s;
-   if (lex.isOK())
+   if (lex)
status = static_cast(s);
 }
 
Index: src/insets/insetnote.C
===
--- src/insets/insetnote.C  (revision 17394)
+++ src/insets/insetnote.C  (working copy)
@@ -105,7 +105,7 @@
 {
string label;
lex >> label;
-   if (lex.isOK())
+   if (lex)
type = notetranslator().find(label);
 }
 
Index: src/insets/insettabular.C
===
--- src/insets/insettabular.C   (revision 17394)
+++ src/insets/insettabular.C   (working copy)
@@ -230,11 +230,11 @@
 
lex.next();
string token = lex.getString();
-   while (lex.isOK() && (token != "\\end_inset")) {
+   while (lex && token != "\\end_inset") {
lex.next();
token = lex.getString();
}
-   if (token != "\\end_inset") {
+   if (!lex) {
lex.printError("Missing \\end_inset at this point. "
   "Read: `$$Token'");
}
Index: src/insets/insetvspace.C
===
--- src/insets/insetvspace.C    (revision 17394)
+++ src/insets/insetvspace.C(working copy)
@@ -88,7 +88,7 @@
BOOST_ASSERT(lex.isOK());
string vsp;
lex >> vsp;
-   if (lex.isOK())
+   if (lex)
space_ = VSpace(vsp);
 
string end_token;
@@ -257,7 +257,7 @@
 
string vsp;
lex >> vsp;
-   if (lex.isOK())
+   if (lex)
vspace = VSpace(vsp);
 }
 
Index: src/lyxlex.C
===
--- src/lyxlex.C(revision 17394)
+++ src/lyxlex.C(working copy)
@@ -53,7 +53,7 @@
 
 bool LyXLex::isOK() const
 {
-   return pimpl_->is.good();
+   return pimpl_->inputAvailable();
 }
 
 
@@ -124,8 +124,16 @@
 
 int LyXLex::getInteger() const
 {
+   lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_->printError("integer token missing");
+   return -1;
+   }
+
if (isStrInt(pimpl_->getString()))
return convert(pimpl_->getString());
+
+   lastReadOk_ = false;
pimpl_->printError("Bad integer `$$Token'");
return -1;
 }
@@ -136,9 +144,17 @@
// replace comma with dot in case the file was written with
// the wron

Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-04 Thread Abdelrazak Younes

Lars Gullik Bjønnes wrote:

Bernhard Roider <[EMAIL PROTECTED]> writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to

| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.


Please check the archive. Bernhard has fixed many bugs already and we 
(Bo, Georg, Peter and Myself) have reviewed all of his former patch.




I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.


He has more than proved himself IMHO.



In the meantime we should all help with reviewing your patches and do
the commit for you.


Of course that's what we have done for the last month or two...

Abdel.


If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.





Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Andre Poenitz
On Fri, Mar 02, 2007 at 11:41:45PM +0100, Bernhard Roider wrote:
 The rule for using the lexer:
 
 if you want to know if the lexer still has data to read (either from the 
 stream or from the pushed token) then use lex.isOK().

Why not lex.dataAvailable() or something similar?

Andre'


Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider

Andre Poenitz wrote:

On Fri, Mar 02, 2007 at 11:41:45PM +0100, Bernhard Roider wrote:

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed token) then use lex.isOK().


Why not lex.dataAvailable() or something similar?


That's because i tried to preserve the current interface best.

Bernhard



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Lars Gullik Bjønnes
Bernhard Roider [EMAIL PROTECTED] writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to
| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.

I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.

In the meantime we should all help with reviewing your patches and do
the commit for you. If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.

-- 
Lgb


Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider
);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == width) {
lex.next();
width = LyXLength(lex.getString());
@@ -606,10 +612,11 @@
lyxerr  InsetBox::Read: Missing 'width'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == special) {
lex.next();
special = lex.getString();
@@ -617,10 +624,11 @@
lyxerr  InsetBox::Read: Missing 'special'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == height) {
lex.next();
height = LyXLength(lex.getString());
@@ -628,10 +636,11 @@
lyxerr  InsetBox::Read: Missing 'height'-tag!  endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == height_special) {
lex.next();
height_special = lex.getString();
Index: src/insets/insetert.C
===
--- src/insets/insetert.C   (revision 17394)
+++ src/insets/insetert.C   (working copy)
@@ -466,7 +466,7 @@
 
int s;
lex  s;
-   if (lex.isOK())
+   if (lex)
status = static_castInsetCollapsable::CollapseStatus(s);
 }
 
Index: src/insets/insetnote.C
===
--- src/insets/insetnote.C  (revision 17394)
+++ src/insets/insetnote.C  (working copy)
@@ -105,7 +105,7 @@
 {
string label;
lex  label;
-   if (lex.isOK())
+   if (lex)
type = notetranslator().find(label);
 }
 
Index: src/insets/insettabular.C
===
--- src/insets/insettabular.C   (revision 17394)
+++ src/insets/insettabular.C   (working copy)
@@ -230,11 +230,11 @@
 
lex.next();
string token = lex.getString();
-   while (lex.isOK()  (token != \\end_inset)) {
+   while (lex  token != \\end_inset) {
lex.next();
token = lex.getString();
}
-   if (token != \\end_inset) {
+   if (!lex) {
lex.printError(Missing \\end_inset at this point. 
   Read: `$$Token');
}
Index: src/insets/insetvspace.C
===
--- src/insets/insetvspace.C(revision 17394)
+++ src/insets/insetvspace.C(working copy)
@@ -88,7 +88,7 @@
BOOST_ASSERT(lex.isOK());
string vsp;
lex  vsp;
-   if (lex.isOK())
+   if (lex)
space_ = VSpace(vsp);
 
string end_token;
@@ -257,7 +257,7 @@
 
string vsp;
lex  vsp;
-   if (lex.isOK())
+   if (lex)
vspace = VSpace(vsp);
 }
 
Index: src/kbmap.C
===
--- src/kbmap.C (revision 17394)
+++ src/kbmap.C (working copy)
@@ -141,7 +141,7 @@
}
 
FuncRequest func = lyxaction.lookupFunc(cmd);
-   if (func. action == LFUN_UNKNOWN_ACTION) {
+   if (func.action == LFUN_UNKNOWN_ACTION) {
lexrc.printError(BN_BIND: Unknown LyX
  function `$$Token');
error = true;
Index: src/lyxlex.C
===
--- src/lyxlex.C(revision 17394)
+++ src/lyxlex.C(working copy)
@@ -53,7 +53,7 @@
 
 bool LyXLex::isOK() const
 {
-   return pimpl_-is.good();
+   return pimpl_-inputAvailable();
 }
 
 
@@ -124,8 +124,16 @@
 
 int LyXLex::getInteger() const
 {
+   lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_-printError(integer token missing);
+   return -1;
+   }
+
if (isStrInt(pimpl_-getString()))
return convertint(pimpl_-getString());
+
+   lastReadOk_ = false;
pimpl_-printError(Bad integer `$$Token');
return -1;
 }
@@ -136,9 +144,17 @@
// replace comma with dot in case the file was written with
// the wrong locale (should be rare, but is easy enough to
// avoid).
+   lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_

Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider

Lars Gullik Bjønnes wrote:

Bernhard Roider [EMAIL PROTECTED] writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to

| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.

I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.

In the meantime we should all help with reviewing your patches and do
the commit for you. If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.



Ok, then here's the patch with const methods and mutable member variable. It 
fixes bug #3293.

Bernhard



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-03 Thread Lars Gullik Bjønnes
Bernhard Roider [EMAIL PROTECTED] writes:

| Ok, then here's the patch with const methods and mutable member
| variable. It fixes bug #3293.

The patch does a lot of small code shuffling that might change
behavior, so it porbably needs some testing. I'll leave it up to RM if
this should be applied or not.

The patch _looks_ good, I think I only found two nit-picks:

| Index: src/kbmap.C
| ===
| --- src/kbmap.C   (revision 17394)
| +++ src/kbmap.C   (working copy)
| @@ -141,7 +141,7 @@
|   }
|  
|   FuncRequest func = lyxaction.lookupFunc(cmd);
| - if (func. action == LFUN_UNKNOWN_ACTION) {
| + if (func.action == LFUN_UNKNOWN_ACTION) {
|   lexrc.printError(BN_BIND: Unknown LyX
| function `$$Token');
|   error = true;

Nice catch. This hunk should be applied right away.

| Index: src/lyxlex.C
| ===
| --- src/lyxlex.C  (revision 17394)
| +++ src/lyxlex.C  (working copy)
| @@ -146,13 +162,23 @@
|  
|  string const LyXLex::getString() const
|  {
| + lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
| +
| + if (lastReadOk_)
|   return pimpl_-getString();
| +
| + return string();

This should just be return string();

|  }
|  
|  
|  docstring const LyXLex::getDocString() const
|  {
| - return pimpl_-getDocString();
| + lastReadOk_ = pimpl_-status == LEX_DATA || pimpl_-status == LEX_TOKEN;
| + 
| + if (lastReadOk_)
| + return pimpl_-getDocString();
| +
| + return docstring(from_utf8());

Similar here return docstring();

-- 
Lgb



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Andre Poenitz
On Fri, Mar 02, 2007 at 11:41:45PM +0100, Bernhard Roider wrote:
> >The rule for using the lexer:
> >
> >if you want to know if the lexer still has data to read (either from the 
> >stream or from the pushed token) then use "lex.isOK()".

Why not lex.dataAvailable() or something similar?

Andre'


Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider

Andre Poenitz wrote:

On Fri, Mar 02, 2007 at 11:41:45PM +0100, Bernhard Roider wrote:

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed token) then use "lex.isOK()".


Why not lex.dataAvailable() or something similar?


That's because i tried to preserve the current interface best.

Bernhard



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Lars Gullik Bjønnes
Bernhard Roider <[EMAIL PROTECTED]> writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to
| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.

I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.

In the meantime we should all help with reviewing your patches and do
the commit for you. If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.

-- 
Lgb


Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider
  lex.next();
use_parbox = lex.getInteger();
@@ -595,10 +600,11 @@
lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "width") {
lex.next();
width = LyXLength(lex.getString());
@@ -606,10 +612,11 @@
lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "special") {
lex.next();
special = lex.getString();
@@ -617,10 +624,11 @@
lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "height") {
lex.next();
height = LyXLength(lex.getString());
@@ -628,10 +636,11 @@
lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "height_special") {
lex.next();
height_special = lex.getString();
Index: src/insets/insetert.C
===
--- src/insets/insetert.C   (revision 17394)
+++ src/insets/insetert.C   (working copy)
@@ -466,7 +466,7 @@
 
int s;
lex >> s;
-   if (lex.isOK())
+   if (lex)
status = static_cast(s);
 }
 
Index: src/insets/insetnote.C
===
--- src/insets/insetnote.C  (revision 17394)
+++ src/insets/insetnote.C  (working copy)
@@ -105,7 +105,7 @@
 {
string label;
lex >> label;
-   if (lex.isOK())
+   if (lex)
type = notetranslator().find(label);
 }
 
Index: src/insets/insettabular.C
===
--- src/insets/insettabular.C   (revision 17394)
+++ src/insets/insettabular.C   (working copy)
@@ -230,11 +230,11 @@
 
lex.next();
string token = lex.getString();
-   while (lex.isOK() && (token != "\\end_inset")) {
+   while (lex && token != "\\end_inset") {
lex.next();
token = lex.getString();
}
-   if (token != "\\end_inset") {
+   if (!lex) {
lex.printError("Missing \\end_inset at this point. "
   "Read: `$$Token'");
}
Index: src/insets/insetvspace.C
===
--- src/insets/insetvspace.C(revision 17394)
+++ src/insets/insetvspace.C(working copy)
@@ -88,7 +88,7 @@
BOOST_ASSERT(lex.isOK());
string vsp;
lex >> vsp;
-   if (lex.isOK())
+   if (lex)
space_ = VSpace(vsp);
 
string end_token;
@@ -257,7 +257,7 @@
 
string vsp;
lex >> vsp;
-   if (lex.isOK())
+   if (lex)
vspace = VSpace(vsp);
 }
 
Index: src/kbmap.C
===
--- src/kbmap.C (revision 17394)
+++ src/kbmap.C (working copy)
@@ -141,7 +141,7 @@
}
 
FuncRequest func = lyxaction.lookupFunc(cmd);
-   if (func. action == LFUN_UNKNOWN_ACTION) {
+   if (func.action == LFUN_UNKNOWN_ACTION) {
lexrc.printError("BN_BIND: Unknown LyX"
 " function `$$Token'");
error = true;
Index: src/lyxlex.C
===
--- src/lyxlex.C(revision 17394)
+++ src/lyxlex.C(working copy)
@@ -53,7 +53,7 @@
 
 bool LyXLex::isOK() const
 {
-   return pimpl_->is.good();
+   return pimpl_->inputAvailable();
 }
 
 
@@ -124,8 +124,16 @@
 
 int LyXLex::getInteger() const
 {
+   lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+   if (!lastReadOk_) {
+   pimpl_->printError("integer token missing");
+   return -1;
+   }
+
  

Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Bernhard Roider

Lars Gullik Bjønnes wrote:

Bernhard Roider <[EMAIL PROTECTED]> writes:

| Hello Lars,
| 
| as Abdel suggested i would like to ask you for SVN commit access, to

| be able to commit my contributions by myself.

I am a bit reluctant, especially since (pardon me if wrong) you havent
contributed much yet, and I have not seen/reviewed any of your
patches.

I think it is better if you prove yourself first, and show that you
write code in a way we are comfortable with before you get any such
access.

In the meantime we should all help with reviewing your patches and do
the commit for you. If you show that you have no problem with writing
code our way, you will soon enough get your commit privileges.



Ok, then here's the patch with const methods and mutable member variable. It 
fixes bug #3293.

Bernhard



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-03 Thread Lars Gullik Bjønnes
Bernhard Roider <[EMAIL PROTECTED]> writes:

| Ok, then here's the patch with const methods and mutable member
| variable. It fixes bug #3293.

The patch does a lot of small code shuffling that might change
behavior, so it porbably needs some testing. I'll leave it up to RM if
this should be applied or not.

The patch _looks_ good, I think I only found two nit-picks:

| Index: src/kbmap.C
| ===
| --- src/kbmap.C   (revision 17394)
| +++ src/kbmap.C   (working copy)
| @@ -141,7 +141,7 @@
|   }
|  
|   FuncRequest func = lyxaction.lookupFunc(cmd);
| - if (func. action == LFUN_UNKNOWN_ACTION) {
| + if (func.action == LFUN_UNKNOWN_ACTION) {
|   lexrc.printError("BN_BIND: Unknown LyX"
|" function `$$Token'");
|   error = true;

Nice catch. This hunk should be applied right away.

| Index: src/lyxlex.C
| ===
| --- src/lyxlex.C  (revision 17394)
| +++ src/lyxlex.C  (working copy)
| @@ -146,13 +162,23 @@
|  
|  string const LyXLex::getString() const
|  {
| + lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
| +
| + if (lastReadOk_)
|   return pimpl_->getString();
| +
| + return string("");

This should just be "return string();"

|  }
|  
|  
|  docstring const LyXLex::getDocString() const
|  {
| - return pimpl_->getDocString();
| + lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
| + 
| + if (lastReadOk_)
| + return pimpl_->getDocString();
| +
| + return docstring(from_utf8(""));

Similar here "return docstring();"

-- 
Lgb



[Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Hello all,

today i searched for the reason why the vspace dialog is completely broken as Michael Gerz wrote in 
his mail from 27.02.2007. It turned out that the bug was introduced by the patch that fixed the bug 
that crashed lyx when inset-insert ert was executed from the command buffer.

The lexer has the method isOK() which reflects the status of the stream is.
The operators void* and ! are not really well defined (they depend on the value of is.bad()). What 
is missing is a test if the last reading operation was successful and thus the returned value is valid.

That's what i implemented in this patch.

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the stream or from the pushed 
token) then use lex.isOK().
If you want to test if the last reading operation was successful then use eg. if (lex) {...} or 
unsuccessful then use eg. if (!lex) {...}


an example:

int readParam(LyxLex lex) {

int param = 1; // default value
if (lex.isOK()) { // the lexer has data to read
int p;// temporary variable
lex  p;
if (lex) param = p; // only use the input if the reading 
operation was successful
}
return param;
}


I tested lyx with the attached patch and found no problems, but who knows...

i think this should go in.

comments?


Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() read tokens in a really 
different way! is this intentionally?




Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

the patch...


Bernhard Roider wrote:

Hello all,

today i searched for the reason why the vspace dialog is completely 
broken as Michael Gerz wrote in his mail from 27.02.2007. It turned out 
that the bug was introduced by the patch that fixed the bug that crashed 
lyx when inset-insert ert was executed from the command buffer.

The lexer has the method isOK() which reflects the status of the stream is.
The operators void* and ! are not really well defined (they depend on 
the value of is.bad()). What is missing is a test if the last reading 
operation was successful and thus the returned value is valid.

That's what i implemented in this patch.

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed token) then use lex.isOK().
If you want to test if the last reading operation was successful then 
use eg. if (lex) {...} or unsuccessful then use eg. if (!lex) {...}


an example:

int readParam(LyxLex lex) {

int param = 1; // default value
if (lex.isOK()) { // the lexer has data to read
int p;// temporary variable
lex  p;
if (lex) param = p; // only use the input if the reading 
operation was successful

}
return param;
}


I tested lyx with the attached patch and found no problems, but who 
knows...


i think this should go in.

comments?


Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() 
read tokens in a really different way! is this intentionally?





Index: src/buffer.C
===
--- src/buffer.C(revision 17394)
+++ src/buffer.C(working copy)
@@ -649,7 +649,7 @@
lex.next();
string const token(lex.getString());
 
-   if (!lex.isOK()) {
+   if (!lex) {
Alert::error(_(Document could not be read),
 bformat(_(%1$s could not be read.), 
from_utf8(filename.absFilename(;
return failure;

Index: src/frontends/controllers/ControlLog.C
===
--- src/frontends/controllers/ControlLog.C  (revision 17394)
+++ src/frontends/controllers/ControlLog.C  (working copy)
@@ -43,7 +43,7 @@
 
string logtype, logfile;
lex  logtype;
-   if (lex.isOK()) {
+   if (lex) {
lex.next(true);
logfile = lex.getString();
}
Index: src/frontends/controllers/ControlParagraph.C
===
--- src/frontends/controllers/ControlParagraph.C(revision 17394)
+++ src/frontends/controllers/ControlParagraph.C(working copy)
@@ -53,7 +53,12 @@
} else if (token == update) {
lex.next();
bool const accept = lex.getBool();
-   action = accept ? 1 : 2;
+   if (lex) {
+   action = accept ? 1 : 2;
+   } else {
+   // Unrecognised update option
+   return false;
+   }
} else if (!token.empty()) {
// Unrecognised token
return false;
Index: src/insets/insetbox.C
===
--- src/insets/insetbox.C   (revision 17394)
+++ src/insets/insetbox.C   (working copy)
@@ -531,15 +531,17 @@
if (!lex.isOK())
return;
 
-   if (lex.isOK()) {
-   lex.next();
-   type = lex.getString();
-   }
-   if (!lex.isOK())
+   lex.next();
+   type = lex.getString();
+
+   if (!lex)
return;
+
lex.next();
string token;
token = lex.getString();
+   if (!lex)
+   return;
if (token == position) {
lex.next();
// The [0] is needed. We need the first and only char in
@@ -549,10 +551,11 @@
lyxerr  InsetBox::Read: Missing 'position'-tag!  token  
endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == hor_pos) {
lex.next();
hor_pos = lex.getString()[0];
@@ -560,10 +563,11 @@
lyxerr  InsetBox::Read: Missing 'hor_pos'-tag!  token  
endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == has_inner_box) {
lex.next();
inner_box = lex.getInteger();
@@ -572,10 +576,10 @@
lex.pushToken(token);
}
 
-   if (!lex.isOK

Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Bernhard Roider wrote:
today i searched for the reason why the vspace dialog is completely 
broken as Michael Gerz wrote in his mail from 27.02.2007. 

bug #3293 (http://bugzilla.lyx.org/show_bug.cgi?id=3293)



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Abdelrazak Younes

Bernhard Roider wrote:

Hello all,


[...]

I tested lyx with the attached patch and found no problems, but who 
knows...


i think this should go in.

comments?


Only a tiny one from me:
Instead of remove the constness of getXXX() methods I suggest that you 
make lastReadOk_ mutable..





Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() 
read tokens in a really different way! is this intentionally?


This lex reader is awful in my opinion, it will evntually go in 1.6 if 
we switch to XML.


Abdel.



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Lars Gullik Bjønnes
Bernhard Roider [EMAIL PROTECTED] writes:

| the patch...

I think the var lastReadOk should be mutable, and you should not
remove const from the functions.

| Index: src/lyxlex.h
| ===
| --- src/lyxlex.h  (revision 17394)
| +++ src/lyxlex.h  (working copy)
| @@ -101,16 +101,16 @@
|   int getLineNo() const;
|  
|   ///
| - int getInteger() const;
| + int getInteger();
|   ///
| - bool getBool() const;
| + bool getBool();
|   ///
| - double getFloat() const;
| + double getFloat();
|   ///
| - std::string const getString() const;
| + std::string const getString();
|  
|   ///
| - docstring const getDocString() const;
| + docstring const getDocString();

Do not remove const on these.

|  
|   /** Get a long string, ended by the tag `endtag'.
|   This string can span several lines. The first line
| @@ -162,6 +162,8 @@
|   class Pimpl;
|   ///
|   Pimpl * pimpl_;
| + ///
| + bool lastReadOk_;

make it mutable.

Apart from that I don't have an opinion on the patch.

-- 
Lgb



Re: [Patch] Rework of LyXLex fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Lars Gullik Bjønnes wrote:

Bernhard Roider [EMAIL PROTECTED] writes:

| the patch...

I think the var lastReadOk should be mutable, and you should not
remove const from the functions.



i already thought about that. i will do it.



[Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Hello all,

today i searched for the reason why the vspace dialog is completely broken as Michael Gerz wrote in 
his mail from 27.02.2007. It turned out that the bug was introduced by the patch that fixed the bug 
that crashed lyx when "inset-insert ert" was executed from the command buffer.

The lexer has the method isOK() which reflects the status of the stream is.
The operators void* and ! are not really well defined (they depend on the value of is.bad()). What 
is missing is a test if the last reading operation was successful and thus the returned value is valid.

That's what i implemented in this patch.

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the stream or from the pushed 
token) then use "lex.isOK()".
If you want to test if the last reading operation was successful then use eg. "if (lex) {...}" or 
unsuccessful then use eg. "if (!lex) {...}"


an example:

int readParam(LyxLex ) {

int param = 1; // default value
if (lex.isOK()) { // the lexer has data to read
int p;// temporary variable
lex >> p;
if (lex) param = p; // only use the input if the reading 
operation was successful
}
return param;
}


I tested lyx with the attached patch and found no problems, but who knows...

i think this should go in.

comments?


Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() read tokens in a really 
different way! is this intentionally?




Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

the patch...


Bernhard Roider wrote:

Hello all,

today i searched for the reason why the vspace dialog is completely 
broken as Michael Gerz wrote in his mail from 27.02.2007. It turned out 
that the bug was introduced by the patch that fixed the bug that crashed 
lyx when "inset-insert ert" was executed from the command buffer.

The lexer has the method isOK() which reflects the status of the stream is.
The operators void* and ! are not really well defined (they depend on 
the value of is.bad()). What is missing is a test if the last reading 
operation was successful and thus the returned value is valid.

That's what i implemented in this patch.

The rule for using the lexer:

if you want to know if the lexer still has data to read (either from the 
stream or from the pushed token) then use "lex.isOK()".
If you want to test if the last reading operation was successful then 
use eg. "if (lex) {...}" or unsuccessful then use eg. "if (!lex) {...}"


an example:

int readParam(LyxLex ) {

int param = 1; // default value
if (lex.isOK()) { // the lexer has data to read
int p;// temporary variable
lex >> p;
if (lex) param = p; // only use the input if the reading 
operation was successful

}
return param;
}


I tested lyx with the attached patch and found no problems, but who 
knows...


i think this should go in.

comments?


Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() 
read tokens in a really different way! is this intentionally?





Index: src/buffer.C
===
--- src/buffer.C(revision 17394)
+++ src/buffer.C(working copy)
@@ -649,7 +649,7 @@
lex.next();
string const token(lex.getString());
 
-   if (!lex.isOK()) {
+   if (!lex) {
Alert::error(_("Document could not be read"),
 bformat(_("%1$s could not be read."), 
from_utf8(filename.absFilename(;
return failure;

Index: src/frontends/controllers/ControlLog.C
===
--- src/frontends/controllers/ControlLog.C  (revision 17394)
+++ src/frontends/controllers/ControlLog.C  (working copy)
@@ -43,7 +43,7 @@
 
string logtype, logfile;
lex >> logtype;
-   if (lex.isOK()) {
+   if (lex) {
lex.next(true);
logfile = lex.getString();
}
Index: src/frontends/controllers/ControlParagraph.C
===
--- src/frontends/controllers/ControlParagraph.C(revision 17394)
+++ src/frontends/controllers/ControlParagraph.C(working copy)
@@ -53,7 +53,12 @@
} else if (token == "update") {
lex.next();
bool const accept = lex.getBool();
-   action = accept ? 1 : 2;
+   if (lex) {
+   action = accept ? 1 : 2;
+   } else {
+   // Unrecognised update option
+   return false;
+   }
} else if (!token.empty()) {
// Unrecognised token
return false;
Index: src/insets/insetbox.C
===
--- src/insets/insetbox.C   (revision 17394)
+++ src/insets/insetbox.C   (working copy)
@@ -531,15 +531,17 @@
if (!lex.isOK())
return;
 
-   if (lex.isOK()) {
-   lex.next();
-   type = lex.getString();
-   }
-   if (!lex.isOK())
+   lex.next();
+   type = lex.getString();
+
+   if (!lex)
return;
+
lex.next();
string token;
token = lex.getString();
+   if (!lex)
+   return;
if (token == "position") {
lex.next();
// The [0] is needed. We need the first and only char in
@@ -549,10 +551,11 @@
lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << 
endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (token == "hor_pos") {
lex.next();
hor_pos = lex.getString()[0];
@@ -560,10 +563,11 @@
lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << 
endl;
lex.pushToken(token);
}
-   if (!lex.isOK())
-   return;
+
lex.next();
token = lex.getString();
+   if (!lex)
+   return;
if (t

Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Bernhard Roider wrote:
today i searched for the reason why the vspace dialog is completely 
broken as Michael Gerz wrote in his mail from 27.02.2007. 

bug #3293 (http://bugzilla.lyx.org/show_bug.cgi?id=3293)



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Abdelrazak Younes

Bernhard Roider wrote:

Hello all,


[...]

I tested lyx with the attached patch and found no problems, but who 
knows...


i think this should go in.

comments?


Only a tiny one from me:
Instead of remove the constness of getXXX() methods I suggest that you 
make lastReadOk_ mutable..





Bernhard


PS: The methods LyXLex::Pimpl::next() and LyXLex::Pimpl::nextToken() 
read tokens in a really different way! is this intentionally?


This lex reader is awful in my opinion, it will evntually go in 1.6 if 
we switch to XML.


Abdel.



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Lars Gullik Bjønnes
Bernhard Roider <[EMAIL PROTECTED]> writes:

| the patch...

I think the var "lastReadOk" should be mutable, and you should not
remove const from the functions.

| Index: src/lyxlex.h
| ===
| --- src/lyxlex.h  (revision 17394)
| +++ src/lyxlex.h  (working copy)
| @@ -101,16 +101,16 @@
|   int getLineNo() const;
|  
|   ///
| - int getInteger() const;
| + int getInteger();
|   ///
| - bool getBool() const;
| + bool getBool();
|   ///
| - double getFloat() const;
| + double getFloat();
|   ///
| - std::string const getString() const;
| + std::string const getString();
|  
|   ///
| - docstring const getDocString() const;
| + docstring const getDocString();

Do not remove const on these.

|  
|   /** Get a long string, ended by the tag `endtag'.
|   This string can span several lines. The first line
| @@ -162,6 +162,8 @@
|   class Pimpl;
|   ///
|   Pimpl * pimpl_;
| + ///
| + bool lastReadOk_;

make it mutable.

Apart from that I don't have an opinion on the patch.

-- 
Lgb



Re: [Patch] Rework of LyXLex && fix at least the vspace dialog bug

2007-03-02 Thread Bernhard Roider

Lars Gullik Bjønnes wrote:

Bernhard Roider <[EMAIL PROTECTED]> writes:

| the patch...

I think the var "lastReadOk" should be mutable, and you should not
remove const from the functions.



i already thought about that. i will do it.



Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-18 Thread Michael Gerz

Michael Gerz wrote:

if you place the cursor in front of a vspace inset, it is displayed 
way too high.


I had a look at method metrics in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why 
do we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)


Something strange is going on with space computation :-( I'll come back 
with a better patch latter.


Michael


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-18 Thread Michael Gerz

Michael Gerz wrote:

if you place the cursor in front of a vspace inset, it is displayed 
way too high.


I had a look at method "metrics" in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why 
do we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)


Something strange is going on with space computation :-( I'll come back 
with a better patch latter.


Michael


[PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Hello,

if you place the cursor in front of a vspace inset, it is displayed way 
too high.


I had a look at method metrics in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why do 
we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)

Michael

PS: This was a nice opportunity in order to practice metrics 
computation. I am ready for the rowpainter stuff now :-)
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1189
diff -u -r1.1189 ChangeLog
--- ChangeLog	16 Sep 2005 10:19:02 -	1.1189
+++ ChangeLog	16 Sep 2005 16:46:17 -
@@ -1,3 +1,8 @@
+2005-09-16  Michael Gerz  [EMAIL PROTECTED]
+
+	* insetvspace.C (metrics): compute ascent and descent in a way that
+	the cursor is placed on the same level as the label text 
+
 2005-09-11  Martin Vermeer  [EMAIL PROTECTED]
 
 	* insettabular.C: fixes bug 1765: multicol cell width on screen not
Index: insetvspace.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.18
diff -u -r1.18 insetvspace.C
--- insetvspace.C	12 Sep 2005 14:57:50 -	1.18
+++ insetvspace.C	16 Sep 2005 16:46:17 -
@@ -116,25 +116,25 @@
 
 void InsetVSpace::metrics(MetricsInfo  mi, Dimension  dim) const
 {
-	int size = 10;
-	int const space_size = space_.inPixels(*mi.base.bv);
-
 	LyXFont font;
 	font.decSize();
-	int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+	font.decSize();
+
+	int height = 3 * arrow_size;
 
-	if (space_.length().len().value()  0.0)
-		size = min_size;
-	else
-		size = max(min_size, space_size);
+	if (space_.length().len().value()  0.0)
+		height = max(height, space_.inPixels(*mi.base.bv));
 
-	dim.asc = size / 2;
-	dim.des = size / 2;
 	int w = 0;
 	int a = 0;
 	int d = 0;
-	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
+
+	height = max(height, a * 2 + 1); // one extra pixel at the top
+	height = max(height, d * 2 + 1); // ... and at the bottom
+
+	dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+	dim.des = height - dim.asc; // label text
 	dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
 
 	dim_ = dim;
@@ -150,8 +150,6 @@
 	int const start = y - dim_.asc;
 	int const end   = y + dim_.des;
 
-	// the label to display (if any)
-	string const str = label();
 	// y-values for top arrow
 	int ty1, ty2;
 	// y-values for bottom arrow
@@ -184,8 +182,9 @@
 	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
 
-	pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
-		   str, font, LColor::none, LColor::none);
+	pi.pain.rectText(x + 2 * arrow_size + 5, 
+			 start + (end - start) / 2 + (a - d) / 2,
+			 label(), font, LColor::none, LColor::none);
 
 	// top arrow
 	pi.pain.line(x, ty1, midx, ty2, LColor::added_space);


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Georg Baum
Michael Gerz wrote:

 Hello,
 
 if you place the cursor in front of a vspace inset, it is displayed way
 too high.

Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.

 I had a look at method metrics in insetvspace.C which IMHO is a bit
 confusing (and partially wrong - Why is size set to 10 initially?

This is not needed, but does no harm either.

 Why do 
 we decrease the font size twice but compute some values in between?)

Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.


Georg



Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Georg Baum wrote:


if you place the cursor in front of a vspace inset, it is displayed way
too high.
   


Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.
 

Yes, I did. The LyX cursor is determined by the font size of the 
paragraph; its vertical bar is drawn from maximum ascent to maximum 
descent. To make vspace insets look good, their relative position to the 
baseline must be defined properly. This is what the patch does.



This is not needed, but does no harm either.
 


I know.

Why do 
we decrease the font size twice but compute some values in between?)
   


Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.
 

Aha! Anyway, I hope that the new code is a bit clearer. After all there 
is no magic in it.


Michael


[PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Hello,

if you place the cursor in front of a vspace inset, it is displayed way 
too high.


I had a look at method "metrics" in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why do 
we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)

Michael

PS: This was a nice opportunity in order to practice metrics 
computation. I am ready for the rowpainter stuff now :-)
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1189
diff -u -r1.1189 ChangeLog
--- ChangeLog	16 Sep 2005 10:19:02 -	1.1189
+++ ChangeLog	16 Sep 2005 16:46:17 -
@@ -1,3 +1,8 @@
+2005-09-16  Michael Gerz  <[EMAIL PROTECTED]>
+
+	* insetvspace.C (metrics): compute ascent and descent in a way that
+	the cursor is placed on the same level as the label text 
+
 2005-09-11  Martin Vermeer  <[EMAIL PROTECTED]>
 
 	* insettabular.C: fixes bug 1765: multicol cell width on screen not
Index: insetvspace.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.18
diff -u -r1.18 insetvspace.C
--- insetvspace.C	12 Sep 2005 14:57:50 -	1.18
+++ insetvspace.C	16 Sep 2005 16:46:17 -
@@ -116,25 +116,25 @@
 
 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-	int size = 10;
-	int const space_size = space_.inPixels(*mi.base.bv);
-
 	LyXFont font;
 	font.decSize();
-	int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+	font.decSize();
+
+	int height = 3 * arrow_size;
 
-	if (space_.length().len().value() < 0.0)
-		size = min_size;
-	else
-		size = max(min_size, space_size);
+	if (space_.length().len().value() > 0.0)
+		height = max(height, space_.inPixels(*mi.base.bv));
 
-	dim.asc = size / 2;
-	dim.des = size / 2;
 	int w = 0;
 	int a = 0;
 	int d = 0;
-	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
+
+	height = max(height, a * 2 + 1); // one extra pixel at the top
+	height = max(height, d * 2 + 1); // ... and at the bottom
+
+	dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+	dim.des = height - dim.asc; // label text
 	dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
 
 	dim_ = dim;
@@ -150,8 +150,6 @@
 	int const start = y - dim_.asc;
 	int const end   = y + dim_.des;
 
-	// the label to display (if any)
-	string const str = label();
 	// y-values for top arrow
 	int ty1, ty2;
 	// y-values for bottom arrow
@@ -184,8 +182,9 @@
 	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
 
-	pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
-		   str, font, LColor::none, LColor::none);
+	pi.pain.rectText(x + 2 * arrow_size + 5, 
+			 start + (end - start) / 2 + (a - d) / 2,
+			 label(), font, LColor::none, LColor::none);
 
 	// top arrow
 	pi.pain.line(x, ty1, midx, ty2, LColor::added_space);


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Georg Baum
Michael Gerz wrote:

> Hello,
> 
> if you place the cursor in front of a vspace inset, it is displayed way
> too high.

Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.

> I had a look at method "metrics" in insetvspace.C which IMHO is a bit
> confusing (and partially wrong - Why is size set to 10 initially?

This is not needed, but does no harm either.

> Why do 
> we decrease the font size twice but compute some values in between?)

Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.


Georg



Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Georg Baum wrote:


if you place the cursor in front of a vspace inset, it is displayed way
too high.
   


Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.
 

Yes, I did. The LyX cursor is determined by the font size of the 
paragraph; its vertical bar is drawn from maximum ascent to maximum 
descent. To make vspace insets look good, their relative position to the 
baseline must be defined properly. This is what the patch does.



This is not needed, but does no harm either.
 


I know.

Why do 
we decrease the font size twice but compute some values in between?)
   


Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.
 

Aha! Anyway, I hope that the new code is a bit clearer. After all there 
is no magic in it.


Michael


Re: VSpace and lengths

2004-11-15 Thread Jean-Marc Lasgouttes
 Juergen == Juergen Spitzmueller [EMAIL PROTECTED] writes:

 You should be careful though about the screen representation of
 such a length.

Juergen I think that screen representation will be just o.k. as is.
Juergen We'd just need to delete the deletion of %-units in the
Juergen frontends.

In any case, avoiding to remove %-units will simplify the code, so it
may be the way to go.

JMarc


Re: VSpace and lengths

2004-11-15 Thread Juergen Spitzmueller
Am Montag, 15. November 2004 12:00 schrieb Jean-Marc Lasgouttes:
 Juergen I think that screen representation will be just o.k. as is.
 Juergen We'd just need to delete the deletion of %-units in the
 Juergen frontends.

 In any case, avoiding to remove %-units will simplify the code, so it
 may be the way to go.

Hm, I noticed that LyXGlueLength::asLaTexString does not transform the 
%-values correctly (as LyXLength::asLaTeXString). This would require some 
more coding, and I think I'd rather postpone this to 1.5.

Jürgen


Re: VSpace and lengths

2004-11-15 Thread Jean-Marc Lasgouttes
 Juergen == Juergen Spitzmueller [EMAIL PROTECTED] writes:

Juergen Hm, I noticed that LyXGlueLength::asLaTexString does not
Juergen transform the %-values correctly (as
Juergen LyXLength::asLaTeXString). This would require some more
Juergen coding, and I think I'd rather postpone this to 1.5.

OK.

JMarc


[Patch] gtk VSpace dialog

2004-11-15 Thread John Spray

This patch adds a gtk VSpace dialog, as well as a function in ghelpers
to get a list of units excluding the percentage units.

John
? tmp
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.85
diff -u -p -r1.85 ChangeLog
--- ChangeLog	15 Nov 2004 16:02:57 -	1.85
+++ ChangeLog	15 Nov 2004 21:53:03 -
@@ -1,11 +1,14 @@
 2004-11-15  John Spray  [EMAIL PROTECTED]
 
+	* The VSpace Dialog:
+	  Dialogs.C, Makefile.am, GVSpace.C, GVSpace.h
 	* The Note Dialog:
 	  Dialogs.C, Makefile.am, GNote.C, GNote.h
 	* The Float Dialog:
 	  Dialogs.C, Makefile.am, GFloat.C, GFloat.h
 	* ghelpers.[Ch]: getGTKStockIcon added to choose gtk
-		stock icons for FuncRequests
+		stock icons for FuncRequests, buildLengthNoRelUnitList()
+		to get vector of units not containing %
 	* GToolbar.C: use getGTKStockIcon for toolbutton icons
 	* GMenubar.C: add icons to menu items
 
Index: Dialogs.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/Dialogs.C,v
retrieving revision 1.34
diff -u -p -r1.34 Dialogs.C
--- Dialogs.C	15 Nov 2004 16:02:57 -	1.34
+++ Dialogs.C	15 Nov 2004 21:53:03 -
@@ -87,7 +87,7 @@
 #include GTableCreate.h
 #include GToc.h
 #include GUrl.h
-#include FormVSpace.h
+#include GVSpace.h
 #include FormWrap.h
 
 #ifdef HAVE_LIBAIKSAURUS
@@ -523,8 +523,9 @@ Dialogs::DialogPtr Dialogs::build(string
 		dialog-setView(new GUrl(*dialog));
 		dialog-bc().bp(new NoRepeatedApplyReadOnlyPolicy);
 	} else if (name == vspace) {
+		dialog-bc().view(new GBC(dialog-bc()));
 		dialog-setController(new ControlVSpace(*dialog));
-		dialog-setView(new FormVSpace(*dialog));
+		dialog-setView(new GVSpace(*dialog));
 		dialog-bc().bp(new OkApplyCancelReadOnlyPolicy);
 	} else if (name == wrap) {
 		dialog-setController(new ControlWrap(*dialog));
Index: GVSpace.C
===
RCS file: GVSpace.C
diff -N GVSpace.C
--- /dev/null	1 Jan 1970 00:00:00 -
+++ GVSpace.C	15 Nov 2004 21:53:03 -
@@ -0,0 +1,164 @@
+/**
+ * \file GVSpace.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Spray
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include config.h
+
+#include GVSpace.h
+#include ControlVSpace.h
+#include ghelpers.h
+
+#include libglademm.h
+
+using std::string;
+using std::vector;
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+string defaultUnit(cm);
+} // namespace anon
+
+GVSpace::GVSpace(Dialog  parent)
+	: GViewCBControlVSpace, GViewGladeB(parent, _(VSpace Settings), false)
+{}
+
+
+void GVSpace::doBuild()
+{
+	string const gladeName = findGladeFile(vspace);
+	xml_ = Gnome::Glade::Xml::create(gladeName);
+
+	Gtk::Button * button;
+	xml_-get_widget(Cancel, button);
+	setCancel(button);
+	xml_-get_widget(Insert, button);
+	setOK(button);
+
+	xml_-get_widget(Spacing, spacingcombo_);
+	xml_-get_widget(Value, valuespin_);
+	xml_-get_widget(ValueUnits, valueunitscombo_);
+	xml_-get_widget(Protect, protectcheck_);
+
+	cols_.add(stringcol_);
+
+	PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList());
+
+	spacingcombo_-signal_changed().connect(
+		sigc::mem_fun(*this, GVSpace::onSpacingComboChanged));
+}
+
+
+void GVSpace::PopulateComboBox(Gtk::ComboBox * combo,
+  vectorstring const  strings)
+{
+	Glib::RefPtrGtk::ListStore model = Gtk::ListStore::create(cols_);
+	vectorstring::const_iterator it = strings.begin();
+	vectorstring::const_iterator end = strings.end();
+	for (int rowindex = 0; it != end; ++it, ++rowindex) {
+		Gtk::TreeModel::iterator row = model-append();
+		(*row)[stringcol_] = *it;
+	}
+
+	combo-set_model(model);
+	Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
+	combo-pack_start(*cell, true);
+	combo-add_attribute(*cell, text, 0);
+}
+
+
+void GVSpace::update()
+{
+	// set the right default unit
+	defaultUnit = getDefaultUnit();
+
+	VSpace const space = controller().params();
+
+	int pos = 0;
+	switch (space.kind()) {
+	case VSpace::DEFSKIP:
+		pos = 0;
+		break;
+	case VSpace::SMALLSKIP:
+		pos = 1;
+		break;
+	case VSpace::MEDSKIP:
+		pos = 2;
+		break;
+	case VSpace::BIGSKIP:
+		pos = 3;
+		break;
+	case VSpace::VFILL:
+		pos = 4;
+		break;
+	case VSpace::LENGTH:
+		pos = 5;
+		break;
+	}
+
+	spacingcombo_-set_active(pos);
+
+	protectcheck_-set_active(space.keep());
+
+	bool const custom_vspace = space.kind() == VSpace::LENGTH;
+	if (custom_vspace) {
+		LyXLength length(space.length().asString());
+		valuespin_-get_adjustment()-set_value(length.value());
+		unitsComboFromLength(valueunitscombo_, stringcol_,
+		 length, defaultUnit);
+	} else {
+		valuespin_-get_adjustment()-set_value(0.0f);
+		unitsComboFromLength(valueunitscombo_, stringcol_,
+		 LyXLength

Re: VSpace and lengths

2004-11-15 Thread Jean-Marc Lasgouttes
> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

>> You should be careful though about the screen representation of
>> such a length.

Juergen> I think that screen representation will be just o.k. as is.
Juergen> We'd just need to delete the deletion of %-units in the
Juergen> frontends.

In any case, avoiding to remove %-units will simplify the code, so it
may be the way to go.

JMarc


Re: VSpace and lengths

2004-11-15 Thread Juergen Spitzmueller
Am Montag, 15. November 2004 12:00 schrieb Jean-Marc Lasgouttes:
> Juergen> I think that screen representation will be just o.k. as is.
> Juergen> We'd just need to delete the deletion of %-units in the
> Juergen> frontends.
>
> In any case, avoiding to remove %-units will simplify the code, so it
> may be the way to go.

Hm, I noticed that LyXGlueLength::asLaTexString does not transform the 
%-values correctly (as LyXLength::asLaTeXString). This would require some 
more coding, and I think I'd rather postpone this to 1.5.

Jürgen


Re: VSpace and lengths

2004-11-15 Thread Jean-Marc Lasgouttes
> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

Juergen> Hm, I noticed that LyXGlueLength::asLaTexString does not
Juergen> transform the %-values correctly (as
Juergen> LyXLength::asLaTeXString). This would require some more
Juergen> coding, and I think I'd rather postpone this to 1.5.

OK.

JMarc


[Patch] gtk VSpace dialog

2004-11-15 Thread John Spray

This patch adds a gtk VSpace dialog, as well as a function in ghelpers
to get a list of units excluding the percentage units.

John
? tmp
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.85
diff -u -p -r1.85 ChangeLog
--- ChangeLog	15 Nov 2004 16:02:57 -	1.85
+++ ChangeLog	15 Nov 2004 21:53:03 -
@@ -1,11 +1,14 @@
 2004-11-15  John Spray  <[EMAIL PROTECTED]>
 
+	* The VSpace Dialog:
+	  Dialogs.C, Makefile.am, GVSpace.C, GVSpace.h
 	* The Note Dialog:
 	  Dialogs.C, Makefile.am, GNote.C, GNote.h
 	* The Float Dialog:
 	  Dialogs.C, Makefile.am, GFloat.C, GFloat.h
 	* ghelpers.[Ch]: getGTKStockIcon added to choose gtk
-		stock icons for FuncRequests
+		stock icons for FuncRequests, buildLengthNoRelUnitList()
+		to get vector of units not containing "%"
 	* GToolbar.C: use getGTKStockIcon for toolbutton icons
 	* GMenubar.C: add icons to menu items
 
Index: Dialogs.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/Dialogs.C,v
retrieving revision 1.34
diff -u -p -r1.34 Dialogs.C
--- Dialogs.C	15 Nov 2004 16:02:57 -	1.34
+++ Dialogs.C	15 Nov 2004 21:53:03 -
@@ -87,7 +87,7 @@
 #include "GTableCreate.h"
 #include "GToc.h"
 #include "GUrl.h"
-#include "FormVSpace.h"
+#include "GVSpace.h"
 #include "FormWrap.h"
 
 #ifdef HAVE_LIBAIKSAURUS
@@ -523,8 +523,9 @@ Dialogs::DialogPtr Dialogs::build(string
 		dialog->setView(new GUrl(*dialog));
 		dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
 	} else if (name == "vspace") {
+		dialog->bc().view(new GBC(dialog->bc()));
 		dialog->setController(new ControlVSpace(*dialog));
-		dialog->setView(new FormVSpace(*dialog));
+		dialog->setView(new GVSpace(*dialog));
 		dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
 	} else if (name == "wrap") {
 		dialog->setController(new ControlWrap(*dialog));
Index: GVSpace.C
===
RCS file: GVSpace.C
diff -N GVSpace.C
--- /dev/null	1 Jan 1970 00:00:00 -
+++ GVSpace.C	15 Nov 2004 21:53:03 -
@@ -0,0 +1,164 @@
+/**
+ * \file GVSpace.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Spray
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include 
+
+#include "GVSpace.h"
+#include "ControlVSpace.h"
+#include "ghelpers.h"
+
+#include 
+
+using std::string;
+using std::vector;
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+string defaultUnit("cm");
+} // namespace anon
+
+GVSpace::GVSpace(Dialog & parent)
+	: GViewCB<ControlVSpace, GViewGladeB>(parent, _("VSpace Settings"), false)
+{}
+
+
+void GVSpace::doBuild()
+{
+	string const gladeName = findGladeFile("vspace");
+	xml_ = Gnome::Glade::Xml::create(gladeName);
+
+	Gtk::Button * button;
+	xml_->get_widget("Cancel", button);
+	setCancel(button);
+	xml_->get_widget("Insert", button);
+	setOK(button);
+
+	xml_->get_widget("Spacing", spacingcombo_);
+	xml_->get_widget("Value", valuespin_);
+	xml_->get_widget("ValueUnits", valueunitscombo_);
+	xml_->get_widget("Protect", protectcheck_);
+
+	cols_.add(stringcol_);
+
+	PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList());
+
+	spacingcombo_->signal_changed().connect(
+		sigc::mem_fun(*this, ::onSpacingComboChanged));
+}
+
+
+void GVSpace::PopulateComboBox(Gtk::ComboBox * combo,
+  vector const & strings)
+{
+	Glib::RefPtr model = Gtk::ListStore::create(cols_);
+	vector::const_iterator it = strings.begin();
+	vector::const_iterator end = strings.end();
+	for (int rowindex = 0; it != end; ++it, ++rowindex) {
+		Gtk::TreeModel::iterator row = model->append();
+		(*row)[stringcol_] = *it;
+	}
+
+	combo->set_model(model);
+	Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
+	combo->pack_start(*cell, true);
+	combo->add_attribute(*cell, "text", 0);
+}
+
+
+void GVSpace::update()
+{
+	// set the right default unit
+	defaultUnit = getDefaultUnit();
+
+	VSpace const space = controller().params();
+
+	int pos = 0;
+	switch (space.kind()) {
+	case VSpace::DEFSKIP:
+		pos = 0;
+		break;
+	case VSpace::SMALLSKIP:
+		pos = 1;
+		break;
+	case VSpace::MEDSKIP:
+		pos = 2;
+		break;
+	case VSpace::BIGSKIP:
+		pos = 3;
+		break;
+	case VSpace::VFILL:
+		pos = 4;
+		break;
+	case VSpace::LENGTH:
+		pos = 5;
+		break;
+	}
+
+	spacingcombo_->set_active(pos);
+
+	protectcheck_->set_active(space.keep());
+
+	bool const custom_vspace = space.kind() == VSpace::LENGTH;
+	if (custom_vspace) {
+		LyXLength le

Re: VSpace and lengths

2004-11-12 Thread Jean-Marc Lasgouttes
 Juergen == Juergen Spitzmueller [EMAIL PROTECTED] writes:

Juergen What were again the reasons why we have excluded the
Juergen %-lengths from VSpace? They certainly work, and IMO at least
Juergen \textheight is highly sensible.

I guess \textheight is the only sensible one. You should be careful
though about the screen representation of such a length.

JMarc


Re: VSpace and lengths

2004-11-12 Thread Juergen Spitzmueller
Jean-Marc Lasgouttes wrote:
 I guess \textheight is the only sensible one. 

Why shouldn't someone find \textwidth sensible? E.g., if he wants produce a 
blank square (for whatever reason). But textheight is certainly the most 
important one.

 You should be careful 
 though about the screen representation of such a length.

I think that screen representation will be just o.k. as is. We'd just need to 
delete the deletion of %-units in the frontends.

Jürgen


Re: VSpace and lengths

2004-11-12 Thread Jean-Marc Lasgouttes
>>>>> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

Juergen> What were again the reasons why we have excluded the
Juergen> %-lengths from VSpace? They certainly work, and IMO at least
Juergen> \textheight is highly sensible.

I guess \textheight is the only sensible one. You should be careful
though about the screen representation of such a length.

JMarc


Re: VSpace and lengths

2004-11-12 Thread Juergen Spitzmueller
Jean-Marc Lasgouttes wrote:
> I guess \textheight is the only sensible one. 

Why shouldn't someone find \textwidth sensible? E.g., if he wants produce a 
blank square (for whatever reason). But textheight is certainly the most 
important one.

> You should be careful 
> though about the screen representation of such a length.

I think that screen representation will be just o.k. as is. We'd just need to 
delete the deletion of %-units in the frontends.

Jürgen


VSpace and lengths

2004-11-11 Thread Juergen Spitzmueller
What were again the reasons why we have excluded the %-lengths from VSpace? 
They certainly work, and IMO at least \textheight is highly sensible.

Jürgen


VSpace and lengths

2004-11-11 Thread Juergen Spitzmueller
What were again the reasons why we have excluded the %-lengths from VSpace? 
They certainly work, and IMO at least \textheight is highly sensible.

Jürgen


Re: [PATCH] Inset VSpace for tex2lyx

2003-12-09 Thread Georg Baum
Am Montag, 8. Dezember 2003 10:20 schrieb Andre Poenitz:
 On Sat, Dec 06, 2003 at 10:16:01PM +0100, Georg Baum wrote:
  Comments?

 Looks good.

Attached is a rediffed version against current cvs.
Could you please apply this one?

Georg
Index: lib/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.549
diff -u -p -r1.549 ChangeLog
--- lib/ChangeLog	2003/12/08 15:46:16	1.549
+++ lib/ChangeLog	2003/12/09 19:47:07
@@ -1,3 +1,7 @@
+2003-12-08  Georg Baum  [EMAIL PROTECTED]
+
+	* reLyX/syntax.default: add \psfrag and \psfrag*
+
 2003-12-08  Jean-Marc Lasgouttes  [EMAIL PROTECTED]
 
 	* CREDITS: add Ronald Florence
Index: lib/reLyX/syntax.default
===
RCS file: /cvs/lyx/lyx-devel/lib/reLyX/syntax.default,v
retrieving revision 1.7
diff -u -p -r1.7 syntax.default
--- lib/reLyX/syntax.default	2003/02/11 13:32:13	1.7
+++ lib/reLyX/syntax.default	2003/12/09 19:47:14
@@ -545,6 +545,8 @@ $$
 \providecommand{}[][]{}
 \providecommand*{}[][]{}
 \ps
+\psfrag{}[][][][]{translate}
+\psfrag*{}[][][][]{translate}
 \pushtabs
 % \put(,){} %picture
 % \qbezier[](,)(,)(,) %picture
Index: src/tex2lyx/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.42
diff -u -p -r1.42 ChangeLog
--- src/tex2lyx/ChangeLog	2003/11/19 10:35:50	1.42
+++ src/tex2lyx/ChangeLog	2003/12/09 19:47:26
@@ -1,3 +1,9 @@
+2003-12-08  Georg Baum  [EMAIL PROTECTED]
+
+	* text.C: Use the new VSpace inset (fixes a bug with added_space top)
+	* text.C: Fix \= in tabbing env again
+	* text.C: Fix invocation of parse_command()
+
 2003-11-18  Georg Baum  [EMAIL PROTECTED]
 
 	* tex2lyx.C:
Index: src/tex2lyx/Makefile.am
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/Makefile.am,v
retrieving revision 1.15
diff -u -p -r1.15 Makefile.am
--- src/tex2lyx/Makefile.am	2003/10/17 23:41:14	1.15
+++ src/tex2lyx/Makefile.am	2003/12/09 19:47:26
@@ -18,6 +19,7 @@ BUILT_SOURCES = \
 	FloatList.C \
 	Floating.C \
 	counters.C \
+	lengthcommon.C \
 	lyxlayout.h \
 	lyxlayout.C \
 	lyxtextclass.C \
Index: src/tex2lyx/text.C
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/text.C,v
retrieving revision 1.28
diff -u -p -r1.28 text.C
--- src/tex2lyx/text.C	2003/11/19 10:35:50	1.28
+++ src/tex2lyx/text.C	2003/12/09 19:47:34
@@ -16,6 +16,7 @@
 #include tex2lyx.h
 #include context.h
 #include FloatList.h
+#include lengthcommon.h
 #include support/lstrings.h
 #include support/tostr.h
 #include support/filetools.h
@@ -103,45 +104,80 @@ mapstring, string split_map(string con
 	return res;
 }
 
-// A simple function to translate a latex length to something lyx can
-// understand. Not perfect, but rather best-effort.
-string translate_len(string const  len)
+
+/*!
+ * Split a LaTeX length into value and unit.
+ * The latter can be a real unit like pt, or a latex length variable
+ * like \textwidth. The unit may contain additional stuff like glue
+ * lengths, but we don't care, because such lengths are ERT anyway.
+ * \return true if \param value and \param unit are valid.
+ */
+bool splitLatexLength(string const  len, string  value, string  unit)
 {
-	const string::size_type i = len.find_first_not_of( -0123456789.,);
+	if (len.empty())
+		return false;
+	const string::size_type i = len.find_first_not_of( -+0123456789.,);
 	//'4,5' is a valid LaTeX length number. Change it to '4.5'
 	string const length = lyx::support::subst(len, ',', '.');
-	// a normal length
-	if (i == string::npos || len[i]  != '\\')
-		return length;
-	double val;
+	if (i == string::npos)
+		return false;
 	if (i == 0) {
-		// We had something like \textwidth without a factor
-		val = 100;
+		if (len[0] == '\\') {
+			// We had something like \textwidth without a factor
+			value = 1.0;
+		} else {
+			return false;
+		}
 	} else {
-		istringstream iss(string(length, 0, i));
-		iss  val;
-		val = val * 100;
+		value = trim(string(length, 0, i));
 	}
+	if (value == -)
+		value = -1.0;
+	// 'cM' is a valid LaTeX length unit. Change it to 'cm'
+	if (lyx::support::contains(len, '\\'))
+		unit = trim(string(len, i));
+	else
+		unit = lyx::support::lowercase(trim(string(len, i)));
+	return true;
+}
+
+
+// A simple function to translate a latex length to something lyx can
+// understand. Not perfect, but rather best-effort.
+string translate_len(string const  length)
+{
+	string unit;
+	string valstring;
+	// If the input is invalid, return what we have.
+	if (!splitLatexLength(length, valstring, unit))
+		return length;
+	// LyX uses percent values
+	double value;
+	istringstream iss(valstring);
+	iss  value;
+	value *= 100;
 	ostringstream oss;
-	oss  val;
-	string const valstring = oss.str();
-	const string::size_type i2 = length.find( , i

Re: [PATCH] Inset VSpace for tex2lyx

2003-12-09 Thread Georg Baum
Am Montag, 8. Dezember 2003 10:20 schrieb Andre Poenitz:
> On Sat, Dec 06, 2003 at 10:16:01PM +0100, Georg Baum wrote:
> > Comments?
>
> Looks good.

Attached is a rediffed version against current cvs.
Could you please apply this one?

Georg
Index: lib/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.549
diff -u -p -r1.549 ChangeLog
--- lib/ChangeLog	2003/12/08 15:46:16	1.549
+++ lib/ChangeLog	2003/12/09 19:47:07
@@ -1,3 +1,7 @@
+2003-12-08  Georg Baum  <[EMAIL PROTECTED]>
+
+	* reLyX/syntax.default: add \psfrag and \psfrag*
+
 2003-12-08  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* CREDITS: add Ronald Florence
Index: lib/reLyX/syntax.default
===
RCS file: /cvs/lyx/lyx-devel/lib/reLyX/syntax.default,v
retrieving revision 1.7
diff -u -p -r1.7 syntax.default
--- lib/reLyX/syntax.default	2003/02/11 13:32:13	1.7
+++ lib/reLyX/syntax.default	2003/12/09 19:47:14
@@ -545,6 +545,8 @@ $$
 \providecommand{}[][]{}
 \providecommand*{}[][]{}
 \ps
+\psfrag{}[][][][]{translate}
+\psfrag*{}[][][][]{translate}
 \pushtabs
 % \put(,){} %picture
 % \qbezier[](,)(,)(,) %picture
Index: src/tex2lyx/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.42
diff -u -p -r1.42 ChangeLog
--- src/tex2lyx/ChangeLog	2003/11/19 10:35:50	1.42
+++ src/tex2lyx/ChangeLog	2003/12/09 19:47:26
@@ -1,3 +1,9 @@
+2003-12-08  Georg Baum  <[EMAIL PROTECTED]>
+
+	* text.C: Use the new VSpace inset (fixes a bug with added_space top)
+	* text.C: Fix \= in tabbing env again
+	* text.C: Fix invocation of parse_command()
+
 2003-11-18  Georg Baum  <[EMAIL PROTECTED]>
 
 	* tex2lyx.C:
Index: src/tex2lyx/Makefile.am
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/Makefile.am,v
retrieving revision 1.15
diff -u -p -r1.15 Makefile.am
--- src/tex2lyx/Makefile.am	2003/10/17 23:41:14	1.15
+++ src/tex2lyx/Makefile.am	2003/12/09 19:47:26
@@ -18,6 +19,7 @@ BUILT_SOURCES = \
 	FloatList.C \
 	Floating.C \
 	counters.C \
+	lengthcommon.C \
 	lyxlayout.h \
 	lyxlayout.C \
 	lyxtextclass.C \
Index: src/tex2lyx/text.C
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/text.C,v
retrieving revision 1.28
diff -u -p -r1.28 text.C
--- src/tex2lyx/text.C	2003/11/19 10:35:50	1.28
+++ src/tex2lyx/text.C	2003/12/09 19:47:34
@@ -16,6 +16,7 @@
 #include "tex2lyx.h"
 #include "context.h"
 #include "FloatList.h"
+#include "lengthcommon.h"
 #include "support/lstrings.h"
 #include "support/tostr.h"
 #include "support/filetools.h"
@@ -103,45 +104,80 @@ map<string, string> split_map(string con
 	return res;
 }
 
-// A simple function to translate a latex length to something lyx can
-// understand. Not perfect, but rather best-effort.
-string translate_len(string const & len)
+
+/*!
+ * Split a LaTeX length into value and unit.
+ * The latter can be a real unit like "pt", or a latex length variable
+ * like "\textwidth". The unit may contain additional stuff like glue
+ * lengths, but we don't care, because such lengths are ERT anyway.
+ * \return true if \param value and \param unit are valid.
+ */
+bool splitLatexLength(string const & len, string & value, string & unit)
 {
-	const string::size_type i = len.find_first_not_of(" -0123456789.,");
+	if (len.empty())
+		return false;
+	const string::size_type i = len.find_first_not_of(" -+0123456789.,");
 	//'4,5' is a valid LaTeX length number. Change it to '4.5'
 	string const length = lyx::support::subst(len, ',', '.');
-	// a normal length
-	if (i == string::npos || len[i]  != '\\')
-		return length;
-	double val;
+	if (i == string::npos)
+		return false;
 	if (i == 0) {
-		// We had something like \textwidth without a factor
-		val = 100;
+		if (len[0] == '\\') {
+			// We had something like \textwidth without a factor
+			value = "1.0";
+		} else {
+			return false;
+		}
 	} else {
-		istringstream iss(string(length, 0, i));
-		iss >> val;
-		val = val * 100;
+		value = trim(string(length, 0, i));
 	}
+	if (value == "-")
+		value = "-1.0";
+	// 'cM' is a valid LaTeX length unit. Change it to 'cm'
+	if (lyx::support::contains(len, '\\'))
+		unit = trim(string(len, i));
+	else
+		unit = lyx::support::lowercase(trim(string(len, i)));
+	return true;
+}
+
+
+// A simple function to translate a latex length to something lyx can
+// understand. Not perfect, but rather best-effort.
+string translate_len(string const & length)
+{
+	string unit;
+	string valstring;
+	// If the input is invalid, return what we have.
+	if (!splitLatexLength(length, val

Re: [PATCH] Inset VSpace for tex2lyx

2003-12-08 Thread Andre Poenitz
On Sat, Dec 06, 2003 at 10:16:01PM +0100, Georg Baum wrote:
 Comments?

Looks good.

Andre'


Re: [PATCH] Inset VSpace for tex2lyx

2003-12-08 Thread Andre Poenitz
On Sat, Dec 06, 2003 at 10:16:01PM +0100, Georg Baum wrote:
> Comments?

Looks good.

Andre'


[PATCH] Inset VSpace for tex2lyx

2003-12-06 Thread Georg Baum
The attached patch makes tex2lyx output an Inset VSpace where possible for 
vertical spaces. Unfortunately it needed more code than I thought to handle 
corner cases correctly. There are some overlaps with lyxlength.C 
(translate_len() could vanish), but lyxlength.C needs some bufferview 
stuff, so this cannot be used in the current form for tex2lyx.
However, I think that in the long term the length handling in LyX should be 
unified. See the comment about text% in lengthcommon.h. I also see no 
reason to disallow the use of \textheight etc. in the vspace inset, if 
literal lengths are allowed.

A few testcases can be found in vspace-test2.tex.

Comments?

Georg
Index: lib/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.548
diff -u -p -r1.548 ChangeLog
--- lib/ChangeLog	2003/12/06 09:31:29	1.548
+++ lib/ChangeLog	2003/12/06 20:30:03
@@ -1,3 +1,7 @@
+2003-12-06  Georg Baum  [EMAIL PROTECTED]
+
+	* reLyX/syntax.default: add \psfrag and \psfrag*
+
 2003-12-06  Martin Vermeer  [EMAIL PROTECTED]
 
 	* db_stdclass.inc:
Index: lib/reLyX/syntax.default
===
RCS file: /cvs/lyx/lyx-devel/lib/reLyX/syntax.default,v
retrieving revision 1.7
diff -u -p -r1.7 syntax.default
--- lib/reLyX/syntax.default	2003/02/11 13:32:13	1.7
+++ lib/reLyX/syntax.default	2003/12/06 20:30:11
@@ -545,6 +545,8 @@ $$
 \providecommand{}[][]{}
 \providecommand*{}[][]{}
 \ps
+\psfrag{}[][][][]{translate}
+\psfrag*{}[][][][]{translate}
 \pushtabs
 % \put(,){} %picture
 % \qbezier[](,)(,)(,) %picture
Index: src/tex2lyx/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.42
diff -u -p -r1.42 ChangeLog
--- src/tex2lyx/ChangeLog	2003/11/19 10:35:50	1.42
+++ src/tex2lyx/ChangeLog	2003/12/06 20:30:24
@@ -1,3 +1,14 @@
+2003-12-06  Georg Baum  [EMAIL PROTECTED]
+
+	* text.C: Use the new VSpace inset (fixes a bug with added_space top)
+	* text.C: Fix \= in tabbing env again
+	* text.C: Fix invocation of parse_command()
+
 2003-11-18  Georg Baum  [EMAIL PROTECTED]
 
 	* tex2lyx.C:
Index: src/tex2lyx/Makefile.am
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/Makefile.am,v
retrieving revision 1.15
diff -u -p -r1.15 Makefile.am
--- src/tex2lyx/Makefile.am	2003/10/17 23:41:14	1.15
+++ src/tex2lyx/Makefile.am	2003/12/06 20:30:24
@@ -18,6 +19,7 @@ BUILT_SOURCES = \
 	FloatList.C \
 	Floating.C \
 	counters.C \
+	lengthcommon.C \
 	lyxlayout.h \
 	lyxlayout.C \
 	lyxtextclass.C \
Index: src/tex2lyx/text.C
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/text.C,v
retrieving revision 1.28
diff -u -p -r1.28 text.C
--- src/tex2lyx/text.C	2003/11/19 10:35:50	1.28
+++ src/tex2lyx/text.C	2003/12/06 20:30:33
@@ -16,6 +16,7 @@
 #include tex2lyx.h
 #include context.h
 #include FloatList.h
+#include lengthcommon.h
 #include support/lstrings.h
 #include support/tostr.h
 #include support/filetools.h
@@ -103,45 +104,80 @@ mapstring, string split_map(string con
 	return res;
 }
 
-// A simple function to translate a latex length to something lyx can
-// understand. Not perfect, but rather best-effort.
-string translate_len(string const  len)
+
+/*!
+ * Split a LaTeX length into value and unit.
+ * The latter can be a real unit like pt, or a latex length variable
+ * like \textwidth. The unit may contain additional stuff like glue
+ * lengths, but we don't care, because such lengths are ERT anyway.
+ * \return true if \param value and \param unit are valid.
+ */
+bool splitLatexLength(string const  len, string  value, string  unit)
 {
-	const string::size_type i = len.find_first_not_of( -0123456789.,);
+	if (len.empty())
+		return false;
+	const string::size_type i = len.find_first_not_of( -+0123456789.,);
 	//'4,5' is a valid LaTeX length number. Change it to '4.5'
 	string const length = lyx::support::subst(len, ',', '.');
-	// a normal length
-	if (i == string::npos || len[i]  != '\\')
-		return length;
-	double val;
+	if (i == string::npos)
+		return false;
 	if (i == 0) {
-		// We had something like \textwidth without a factor
-		val = 100;
+		if (len[0] == '\\') {
+			// We had something like \textwidth without a factor
+			value = 1.0;
+		} else {
+			return false;
+		}
 	} else {
-		istringstream iss(string(length, 0, i));
-		iss  val;
-		val = val * 100;
+		value = trim(string(length, 0, i));
 	}
+	if (value == -)
+		value = -1.0;
+	// 'cM' is a valid LaTeX length unit. Change it to 'cm'
+	if (lyx::support::contains(len, '\\'))
+		unit = trim(string(len, i));
+	else
+		unit = lyx::support::lowercase(trim(string(len, i)));
+	return true;
+}
+
+
+// A simple function to translate a latex length to something lyx can
+// understand. Not perfect, but rather best-effort.
+string

[PATCH] Inset VSpace for tex2lyx

2003-12-06 Thread Georg Baum
The attached patch makes tex2lyx output an Inset VSpace where possible for 
vertical spaces. Unfortunately it needed more code than I thought to handle 
corner cases correctly. There are some overlaps with lyxlength.C 
(translate_len() could vanish), but lyxlength.C needs some bufferview 
stuff, so this cannot be used in the current form for tex2lyx.
However, I think that in the long term the length handling in LyX should be 
unified. See the comment about "text%" in lengthcommon.h. I also see no 
reason to disallow the use of \textheight etc. in the vspace inset, if 
literal lengths are allowed.

A few testcases can be found in vspace-test2.tex.

Comments?

Georg
Index: lib/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.548
diff -u -p -r1.548 ChangeLog
--- lib/ChangeLog	2003/12/06 09:31:29	1.548
+++ lib/ChangeLog	2003/12/06 20:30:03
@@ -1,3 +1,7 @@
+2003-12-06  Georg Baum  <[EMAIL PROTECTED]>
+
+	* reLyX/syntax.default: add \psfrag and \psfrag*
+
 2003-12-06  Martin Vermeer  <[EMAIL PROTECTED]>
 
 	* db_stdclass.inc:
Index: lib/reLyX/syntax.default
===
RCS file: /cvs/lyx/lyx-devel/lib/reLyX/syntax.default,v
retrieving revision 1.7
diff -u -p -r1.7 syntax.default
--- lib/reLyX/syntax.default	2003/02/11 13:32:13	1.7
+++ lib/reLyX/syntax.default	2003/12/06 20:30:11
@@ -545,6 +545,8 @@ $$
 \providecommand{}[][]{}
 \providecommand*{}[][]{}
 \ps
+\psfrag{}[][][][]{translate}
+\psfrag*{}[][][][]{translate}
 \pushtabs
 % \put(,){} %picture
 % \qbezier[](,)(,)(,) %picture
Index: src/tex2lyx/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.42
diff -u -p -r1.42 ChangeLog
--- src/tex2lyx/ChangeLog	2003/11/19 10:35:50	1.42
+++ src/tex2lyx/ChangeLog	2003/12/06 20:30:24
@@ -1,3 +1,14 @@
+2003-12-06  Georg Baum  <[EMAIL PROTECTED]>
+
+	* text.C: Use the new VSpace inset (fixes a bug with added_space top)
+	* text.C: Fix \= in tabbing env again
+	* text.C: Fix invocation of parse_command()
+
 2003-11-18  Georg Baum  <[EMAIL PROTECTED]>
 
 	* tex2lyx.C:
Index: src/tex2lyx/Makefile.am
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/Makefile.am,v
retrieving revision 1.15
diff -u -p -r1.15 Makefile.am
--- src/tex2lyx/Makefile.am	2003/10/17 23:41:14	1.15
+++ src/tex2lyx/Makefile.am	2003/12/06 20:30:24
@@ -18,6 +19,7 @@ BUILT_SOURCES = \
 	FloatList.C \
 	Floating.C \
 	counters.C \
+	lengthcommon.C \
 	lyxlayout.h \
 	lyxlayout.C \
 	lyxtextclass.C \
Index: src/tex2lyx/text.C
===
RCS file: /cvs/lyx/lyx-devel/src/tex2lyx/text.C,v
retrieving revision 1.28
diff -u -p -r1.28 text.C
--- src/tex2lyx/text.C	2003/11/19 10:35:50	1.28
+++ src/tex2lyx/text.C	2003/12/06 20:30:33
@@ -16,6 +16,7 @@
 #include "tex2lyx.h"
 #include "context.h"
 #include "FloatList.h"
+#include "lengthcommon.h"
 #include "support/lstrings.h"
 #include "support/tostr.h"
 #include "support/filetools.h"
@@ -103,45 +104,80 @@ map<string, string> split_map(string con
 	return res;
 }
 
-// A simple function to translate a latex length to something lyx can
-// understand. Not perfect, but rather best-effort.
-string translate_len(string const & len)
+
+/*!
+ * Split a LaTeX length into value and unit.
+ * The latter can be a real unit like "pt", or a latex length variable
+ * like "\textwidth". The unit may contain additional stuff like glue
+ * lengths, but we don't care, because such lengths are ERT anyway.
+ * \return true if \param value and \param unit are valid.
+ */
+bool splitLatexLength(string const & len, string & value, string & unit)
 {
-	const string::size_type i = len.find_first_not_of(" -0123456789.,");
+	if (len.empty())
+		return false;
+	const string::size_type i = len.find_first_not_of(" -+0123456789.,");
 	//'4,5' is a valid LaTeX length number. Change it to '4.5'
 	string const length = lyx::support::subst(len, ',', '.');
-	// a normal length
-	if (i == string::npos || len[i]  != '\\')
-		return length;
-	double val;
+	if (i == string::npos)
+		return false;
 	if (i == 0) {
-		// We had something like \textwidth without a factor
-		val = 100;
+		if (len[0] == '\\') {
+			// We had something like \textwidth without a factor
+			value = "1.0";
+		} else {
+			return false;
+		}
 	} else {
-		istringstream iss(string(length, 0, i));
-		iss >> val;
-		val = val * 100;
+		value = trim(string(length, 0, i));
 	}
+	if (value == "-")
+		value = "-1.0";
+	// 'cM' is a valid LaTeX length unit. Change it to 'cm'
+	if (lyx::support::contains(len, '\\'))
+

Re: vspace ui

2003-12-01 Thread Juergen Spitzmueller
John Levon wrote:
 What on earth is a vspace of none ? Why is it the default ?

Don't know. But it does not make any sense to me either.

 There are missing tooltips it seems ... (qt)

Where?

Jürgen.



Re: vspace ui

2003-12-01 Thread Andre Poenitz
On Mon, Dec 01, 2003 at 12:20:36AM +, John Levon wrote:
 
 What on earth is a vspace of none ? Why is it the default ?

Because we used to have two vspace members in the paragraph parameters
(that skip above/below) which were unused almost all the time and
therefore defaulted to some special value 'NONE'. I don't think we'd
need this value anymore.

Andre'


[PATCH] VSpace cleanup

2003-12-01 Thread Michael Schmitt
Hello,

NONE is a pretty pointless option with a true VSpace inset.

Please check and apply the attached patch.

Thanks, Michael
Index: src/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.1732
diff -u -r1.1732 ChangeLog
--- src/ChangeLog   2003/12/01 00:35:26 1.1732
+++ src/ChangeLog   2003/12/01 09:28:01
@@ -1,3 +1,7 @@
+2003-12-01  Michael Schmitt  [EMAIL PROTECTED]
+
+   * vspace.[Ch]: remove VSpace::NONE
+
 2003-12-01  John Levon  [EMAIL PROTECTED]
 
* BufferView_pimpl.C: fix a crash on exit with
Index: src/vspace.C
===
RCS file: /cvs/lyx/lyx-devel/src/vspace.C,v
retrieving revision 1.79
diff -u -r1.79 vspace.C
--- src/vspace.C2003/11/21 17:31:46 1.79
+++ src/vspace.C2003/12/01 09:28:03
@@ -337,7 +337,7 @@
 //
 
 VSpace::VSpace()
-   : kind_(NONE), len_(), keep_(false)
+   : kind_(DEFSKIP), len_(), keep_(false)
 {}
 
 
@@ -357,7 +357,7 @@
 
 
 VSpace::VSpace(string const  data)
-   : kind_(NONE), len_(), keep_(false)
+   : kind_(DEFSKIP), len_(), keep_(false)
 {
if (data.empty())
return;
@@ -436,7 +436,6 @@
 {
string result;
switch (kind_) {
-   case NONE:  break;
case DEFSKIP:   result = defskip;  break;
case SMALLSKIP: result = smallskip;break;
case MEDSKIP:   result = medskip;  break;
@@ -444,7 +443,7 @@
case VFILL: result = vfill;break;
case LENGTH:result = len_.asString(); break;
}
-   if (keep_  kind_ != NONE  kind_ != DEFSKIP)
+   if (keep_)
result += '*';
return result;
 }
@@ -472,9 +471,6 @@
return keep_ ? \\vspace*{ + len_.asLatexString() + '}'
: \\vspace{ + len_.asLatexString() + '}';
 
-   case NONE:
-   return string();
-
default:
BOOST_ASSERT(false);
return string();
@@ -510,9 +506,6 @@
 
case LENGTH:
return len_.len().inPixels(bv.workWidth());
-
-   case NONE:
-   return 0;
 
default:
BOOST_ASSERT(false);
Index: src/vspace.h
===
RCS file: /cvs/lyx/lyx-devel/src/vspace.h,v
retrieving revision 1.30
diff -u -r1.30 vspace.h
--- src/vspace.h2003/10/06 15:42:43 1.30
+++ src/vspace.h2003/12/01 09:28:03
@@ -24,7 +24,6 @@
 public:
/// The different kinds of spaces.
enum vspace_kind {
-   NONE, /// no added vertical space
DEFSKIP,
SMALLSKIP,
MEDSKIP,
Index: src/frontends/qt2/ChangeLog
===
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.615
diff -u -r1.615 ChangeLog
--- src/frontends/qt2/ChangeLog 2003/12/01 07:54:02 1.615
+++ src/frontends/qt2/ChangeLog 2003/12/01 09:28:12
@@ -1,3 +1,9 @@
+2003-12-01  Michael Schmitt  [EMAIL PROTECTED]
+
+   * QVSpace.C:
+   * QVSpaceDialog.C:
+   * ui/QVSpaceDialogBase.ui: remove VSpace::NONE
+
 2003-12-01  Juergen Spitzmueller  [EMAIL PROTECTED]
 
* QDocumentDialog.[Ch]: (branches) don't insert a coloritem
Index: src/frontends/qt2/QVSpace.C
===
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QVSpace.C,v
retrieving revision 1.3
diff -u -r1.3 QVSpace.C
--- src/frontends/qt2/QVSpace.C 2003/12/01 07:54:02 1.3
+++ src/frontends/qt2/QVSpace.C 2003/12/01 09:28:12
@@ -50,26 +50,23 @@
 {
int item = 0;
switch (space.kind()) {
-   case VSpace::NONE:
-   item = 0;
-   break;
case VSpace::DEFSKIP:
-   item = 1;
+   item = 0;
break;
case VSpace::SMALLSKIP:
-   item = 2;
+   item = 1;
break;
case VSpace::MEDSKIP:
-   item = 3;
+   item = 2;
break;
case VSpace::BIGSKIP:
-   item = 4;
+   item = 3;
break;
case VSpace::VFILL:
-   item = 5;
+   item = 4;
break;
case VSpace::LENGTH:
-   item = 6;
+   item = 5;
break;
}
spacing-setCurrentItem(item);
@@ -96,28 +93,25 @@
LengthCombo * unit,
bool keep)
 {
-   VSpace space = VSpace(VSpace::NONE);
+   VSpace space;
 
switch (spacing) {
case 0:
-   space = VSpace(VSpace::NONE);
-   break;
-   case 1:
space = VSpace(VSpace::DEFSKIP);
break;
-   case 2:
+   case 1

  1   2   >