A bit of the interface cleanup.
Removes the inheritance etc,
Andre'
--
Andr� P�nitz .............................................. [EMAIL PROTECTED]
Index: figureForm.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/figureForm.C,v
retrieving revision 1.10
diff -u -p -r1.10 figureForm.C
--- figureForm.C 2001/09/09 22:02:10 1.10
+++ figureForm.C 2001/11/30 16:47:58
@@ -81,16 +81,10 @@ void FigureApplyCB(FL_OBJECT *, long)
// The standard layout should always be numer 0;
current_view->text->setLayout(current_view, 0);
- current_view->text->
- setParagraph(current_view, 0, 0,
- 0, 0,
- VSpace (0.3 * buffer->params.spacing.getValue(),
- LyXLength::CM),
- VSpace (0.3 *
- buffer->params.spacing.getValue(),
- LyXLength::CM),
- Spacing(),
- LYX_ALIGN_CENTER, string(), 0);
+ LyXLength len(0.3 * buffer->params.spacing.getValue(), LyXLength::CM);
+ current_view->text->setParagraph(current_view, 0, 0, 0, 0,
+ VSpace(len), VSpace(len), Spacing(),
+ LYX_ALIGN_CENTER, string(), 0);
current_view->update(current_view->text,
BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
Index: vspace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vspace.C,v
retrieving revision 1.45
diff -u -p -r1.45 vspace.C
--- vspace.C 2001/11/30 14:57:15 1.45
+++ vspace.C 2001/11/30 16:47:59
@@ -51,6 +51,14 @@ int number_index;
int unit_index;
+LyXLength::UNIT unitFromString(string const & data)
+{
+ int i = 0;
+ while (i < num_units && data != unit_name[i])
+ ++i;
+ return static_cast<LyXLength::UNIT>(i);
+}
+
inline
void lyx_advance(string & data, string::size_type n)
{
@@ -164,6 +172,7 @@ LaTeXLength table[] = {
{ "", 0, 0, 0, 0 } // sentinel, must be empty
};
+
} // namespace anon
const char * stringFromUnit(int unit)
@@ -241,12 +250,12 @@ bool isValidGlueLength(string const & da
// is zero, the corresponding array value is zero or UNIT_NONE,
// so we needn't check this.
if (result) {
- result->val_ = number[1] * val_sign;
- result->unit_ = unit[1];
- result->plus_val_ = number[table[table_index].plus_val_index];
- result->minus_val_ = number[table[table_index].minus_val_index];
- result->plus_unit_ = unit [table[table_index].plus_uni_index];
- result->minus_unit_ = unit [table[table_index].minus_uni_index];
+ result->len_.value (number[1] * val_sign);
+ result->len_.unit (unit[1]);
+ result->plus_.value (number[table[table_index].plus_val_index]);
+ result->plus_.unit (unit [table[table_index].plus_uni_index]);
+ result->minus_.value(number[table[table_index].minus_val_index]);
+ result->minus_.unit (unit [table[table_index].minus_uni_index]);
}
return true;
}
@@ -381,51 +390,44 @@ LyXLength::UNIT LyXLength::unit() const
}
-bool operator==(LyXLength const & l1, LyXLength const & l2)
+void LyXLength::value(double v)
{
- return l1.value() == l2.value() && l1.unit() == l2.unit();
+ val_ = v;
}
-
+
-LyXLength::UNIT unitFromString (string const & data)
+void LyXLength::unit(LyXLength::UNIT u)
{
- int i = 0;
- while (i < num_units && data != unit_name[i])
- ++i;
- return static_cast<LyXLength::UNIT>(i);
+ unit_ = u;
}
+bool operator==(LyXLength const & l1, LyXLength const & l2)
+{
+ return l1.value() == l2.value() && l1.unit() == l2.unit();
+}
+
+
//
// LyXGlueLength
//
-LyXGlueLength::LyXGlueLength(
- double v, LyXLength::UNIT u,
- double pv, LyXLength::UNIT pu,
- double mv, LyXLength::UNIT mu)
- : LyXLength(v, u),
- plus_val_(pv), minus_val_(mv),
- plus_unit_(pu), minus_unit_(mu)
+LyXGlueLength::LyXGlueLength(LyXLength const & len)
+ : len_(len)
{}
+LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus,
+ LyXLength const & minus)
+ : len_(len), plus_(plus), minus_(minus)
+{}
+
+
LyXGlueLength::LyXGlueLength(string const & data)
{
- LyXGlueLength tmp(0.0, PT);
-
- // we should really raise exception here
- if (!isValidGlueLength(data, &tmp))
- ;
-
- val_ = tmp.val_;
- unit_ = tmp.unit_;
- plus_val_ = tmp.plus_val_;
- plus_unit_ = tmp.plus_unit_;
- minus_val_ = tmp.minus_val_;
- minus_unit_ = tmp.minus_unit_;
+ isValidGlueLength(data, this);
}
@@ -433,51 +435,51 @@ string const LyXGlueLength::asString() c
{
ostringstream buffer;
- if (plus_val_ != 0.0)
- if (minus_val_ != 0.0)
- if (unit_ == plus_unit_ && unit_ == minus_unit_)
- if (plus_val_ == minus_val_)
- buffer << val_ << "+-"
- << plus_val_ << unit_name[unit_];
+ if (plus_.value() != 0.0)
+ if (minus_.value() != 0.0)
+ if (len_.unit() == plus_.unit() && len_.unit() ==
+minus_.unit())
+ if (plus_.value() == minus_.value())
+ buffer << len_.value() << "+-"
+ << plus_.value() <<
+unit_name[len_.unit()];
else
- buffer << val_
- << '+' << plus_val_
- << '-' << minus_val_
- << unit_name[unit_];
+ buffer << len_.value()
+ << '+' << plus_.value()
+ << '-' << minus_.value()
+ << unit_name[len_.unit()];
else
- if (plus_unit_ == minus_unit_
- && plus_val_ == minus_val_)
- buffer << val_ << unit_name[unit_]
- << "+-" << plus_val_
- << unit_name[plus_unit_];
+ if (plus_.unit() == minus_.unit()
+ && plus_.value() == minus_.value())
+ buffer << len_.value() <<
+unit_name[len_.unit()]
+ << "+-" << plus_.value()
+ << unit_name[plus_.unit()];
else
- buffer << val_ << unit_name[unit_]
- << '+' << plus_val_
- << unit_name[plus_unit_]
- << '-' << minus_val_
- << unit_name[minus_unit_];
+ buffer << len_.value() <<
+unit_name[len_.unit()]
+ << '+' << plus_.value()
+ << unit_name[plus_.unit()]
+ << '-' << minus_.value()
+ << unit_name[minus_.unit()];
else
- if (unit_ == plus_unit_)
- buffer << val_ << '+' << plus_val_
- << unit_name[unit_];
+ if (len_.unit() == plus_.unit())
+ buffer << len_.value() << '+' << plus_.value()
+ << unit_name[len_.unit()];
else
- buffer << val_ << unit_name[unit_]
- << '+' << plus_val_
- << unit_name[plus_unit_];
+ buffer << len_.value() << unit_name[len_.unit()]
+ << '+' << plus_.value()
+ << unit_name[plus_.unit()];
else
- if (minus_val_ != 0.0)
- if (unit_ == minus_unit_)
- buffer << val_ << '-' << minus_val_
- << unit_name[unit_];
+ if (minus_.value() != 0.0)
+ if (len_.unit() == minus_.unit())
+ buffer << len_.value() << '-' << minus_.value()
+ << unit_name[len_.unit()];
else
- buffer << val_ << unit_name[unit_]
- << '-' << minus_val_
- << unit_name[minus_unit_];
+ buffer << len_.value() << unit_name[len_.unit()]
+ << '-' << minus_.value()
+ << unit_name[minus_.unit()];
else
- buffer << val_ << unit_name[unit_];
+ buffer << len_.value() << unit_name[len_.unit()];
return buffer.str().c_str();
}
@@ -487,61 +489,52 @@ string const LyXGlueLength::asLatexStrin
{
ostringstream buffer;
- if (plus_val_ != 0.0)
- if (minus_val_ != 0.0)
- buffer << val_ << unit_name[unit_]
+ if (plus_.value() != 0.0)
+ if (minus_.value() != 0.0)
+ buffer << len_.value() << unit_name[len_.unit()]
<< " plus "
- << plus_val_ << unit_name[plus_unit_]
+ << plus_.value() << unit_name[plus_.unit()]
<< " minus "
- << minus_val_ << unit_name[minus_unit_];
+ << minus_.value() << unit_name[minus_.unit()];
else
- buffer << val_ << unit_name[unit_]
+ buffer << len_.value() << unit_name[len_.unit()]
<< " plus "
- << plus_val_ << unit_name[plus_unit_];
+ << plus_.value() << unit_name[plus_.unit()];
else
- if (minus_val_ != 0.0)
- buffer << val_ << unit_name[unit_]
+ if (minus_.value() != 0.0)
+ buffer << len_.value() << unit_name[len_.unit()]
<< " minus "
- << minus_val_ << unit_name[minus_unit_];
+ << minus_.value() << unit_name[minus_.unit()];
else
- buffer << val_ << unit_name[unit_];
+ buffer << len_.value() << unit_name[len_.unit()];
return buffer.str().c_str();
}
-
-double LyXGlueLength::plusValue() const
-{
- return plus_val_;
-}
-
-LyXLength::UNIT LyXGlueLength::plusUnit() const
+LyXLength const & LyXGlueLength::len() const
{
- return plus_unit_;
+ return len_;
}
-double LyXGlueLength::minusValue() const
+LyXLength const & LyXGlueLength::plus() const
{
- return minus_val_;
+ return plus_;
}
-LyXLength::UNIT LyXGlueLength::minusUnit() const
+LyXLength const & LyXGlueLength::minus() const
{
- return minus_unit_;
+ return minus_;
}
bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
{
- return l1.value() == l2.value()
- && l1.unit() == l2.unit()
- && l1.plusValue() == l2.plusValue()
- && l1.plusUnit() == l2.plusUnit()
- && l1.minusValue() == l2.minusValue()
- && l1.minusUnit() == l2.minusUnit();
+ return l1.len() == l2.len()
+ && l1.plus() == l2.plus()
+ && l1.minus() == l2.minus();
}
@@ -552,27 +545,27 @@ bool operator==(LyXGlueLength const & l1
//
VSpace::VSpace()
- : kind_(NONE), len_(0.0, LyXLength::PT), keep_(false)
+ : kind_(NONE), len_(), keep_(false)
{}
VSpace::VSpace(vspace_kind k)
- : kind_(k), len_(0.0, LyXLength::PT), keep_(false)
+ : kind_(k), len_(), keep_(false)
{}
-VSpace::VSpace(LyXGlueLength l)
+VSpace::VSpace(LyXLength const & l)
: kind_(LENGTH), len_(l), keep_(false)
{}
-VSpace::VSpace(double v, LyXLength::UNIT u)
- : kind_(LENGTH), len_(v, u), keep_(false)
+VSpace::VSpace(LyXGlueLength const & l)
+ : kind_(LENGTH), len_(l), keep_(false)
{}
VSpace::VSpace(string const & data)
- : kind_(NONE), len_(0.0, LyXLength::PT), keep_(false)
+ : kind_(NONE), len_(), keep_(false)
{
if (data.empty())
return;
@@ -597,7 +590,7 @@ VSpace::VSpace(string const & data)
// without units in added_space_top/bottom.
// Let unit default to centimeters here.
kind_ = LENGTH;
- len_ = LyXGlueLength(value, LyXLength::CM);
+ len_ = LyXGlueLength(LyXLength(value, LyXLength::CM));
}
}
@@ -683,20 +676,13 @@ string const VSpace::asLatexCommand(Buff
int VSpace::inPixels(BufferView * bv) const
{
// Height of a normal line in pixels (zoom factor considered)
- int height = bv->text->defaultHeight(); // [pixels]
- int skip = 0;
- int width = bv->workWidth();
+ int default_height = bv->text->defaultHeight(); // [pixels]
+ int default_skip = 0;
+ int default_width = bv->workWidth();
if (kind_ == DEFSKIP)
- skip = bv->buffer()->params.getDefSkip().inPixels(bv);
+ default_skip = bv->buffer()->params.getDefSkip().inPixels(bv);
- return inPixels(height, skip, width);
-}
-
-
-int VSpace::inPixels(int default_height, int default_skip, int default_width)
- const
-{
// Height of a normal line in pixels (zoom factor considered)
int height = default_height; // [pixels]
@@ -733,10 +719,10 @@ int VSpace::inPixels(int default_height,
// we don't care about sign of value, we
// display negative space with text too
result = 0.0;
- value = len_.value();
+ value = len_.len().value();
int val_sign = value < 0.0 ? -1 : 1;
- switch (len_.unit()) {
+ switch (len_.len().unit()) {
case LyXLength::SP:
// Scaled point: sp = 1/65536 pt
result = zoom * dpi * value
Index: vspace.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vspace.h,v
retrieving revision 1.19
diff -u -p -r1.19 vspace.h
--- vspace.h 2001/11/30 14:57:15 1.19
+++ vspace.h 2001/11/30 16:47:59
@@ -77,17 +77,24 @@ public:
double value() const;
///
LyXLength::UNIT unit() const;
+ ///
+ void value(double);
+ ///
+ void unit(LyXLength::UNIT unit);
+ /// real length in SP
+ void lenght();
+
/// conversion
- virtual string const asString() const;
+ string const asString() const;
///
- virtual string const asLatexString() const;
+ string const asLatexString() const;
/** If "data" is valid, the length represented by it is
stored into "result", if that is not 0. */
friend bool isValidLength(string const & data, LyXLength * result = 0);
-protected:
+private:
///
double val_;
///
@@ -97,8 +104,6 @@ protected:
///
bool operator==(LyXLength const & l1, LyXLength const & l2);
///
-LyXLength::UNIT unitFromString (string const & data);
-///
bool isValidLength(string const & data, LyXLength * result);
///
const char * stringFromUnit(int unit);
@@ -108,15 +113,16 @@ const char * stringFromUnit(int unit);
//
/// LyXGlueLength class
//
-class LyXGlueLength : public LyXLength {
+class LyXGlueLength {
public:
///
- LyXGlueLength(double v,
- LyXLength::UNIT u,
- double pv = 0.0,
- LyXLength::UNIT pu = LyXLength::UNIT_NONE,
- double mv = 0.0,
- LyXLength::UNIT mu = LyXLength::UNIT_NONE);
+ LyXGlueLength() {}
+ ///
+ explicit LyXGlueLength(LyXLength const & len);
+ ///
+ LyXGlueLength(LyXLength const & len,
+ LyXLength const & plus,
+ LyXLength const & minus);
/** "data" must be a decimal number, followed by a unit, and
optional "glue" indicated by "+" and "-". You may abbreviate
@@ -126,19 +132,18 @@ public:
4cm plus 10pt minus 10pt */
explicit LyXGlueLength(string const & data);
- ///
- double plusValue() const;
///
- LyXLength::UNIT plusUnit() const;
+ LyXLength const & len() const;
///
- double minusValue() const;
+ LyXLength const & plus() const;
///
- LyXLength::UNIT minusUnit() const;
+ LyXLength const & minus() const;
+
/// conversion
- virtual string const asString() const;
+ string const asString() const;
///
- virtual string const asLatexString() const;
+ string const asLatexString() const;
/** If "data" is valid, the length represented by it is
@@ -146,15 +151,13 @@ public:
friend bool isValidGlueLength(string const & data,
LyXGlueLength* result = 0);
-protected:
- ///
- double plus_val_;
- ///
- double minus_val_;
- ///
- LyXLength::UNIT plus_unit_;
- ///
- LyXLength::UNIT minus_unit_;
+private:
+ /// the normal vlaue
+ LyXLength len_;
+ /// extra stretch
+ LyXLength plus_;
+ /// extra shrink
+ LyXLength minus_;
};
///
@@ -190,9 +193,9 @@ public:
/// Constructor
explicit VSpace(vspace_kind k);
/// Constructor
- explicit VSpace(LyXGlueLength l);
+ explicit VSpace(LyXLength const & l);
/// Constructor
- explicit VSpace(double v, LyXLength::UNIT u);
+ explicit VSpace(LyXGlueLength const & l);
/// Constructor for reading from a .lyx file
explicit VSpace(string const & data);
@@ -200,7 +203,7 @@ public:
/// access functions
vspace_kind kind() const;
///
- LyXGlueLength length() const;
+ LyXGlueLength length() const;
// a flag that switches between \vspace and \vspace*
bool keep() const;
@@ -216,8 +219,6 @@ public:
string const asLatexCommand(BufferParams const & params) const;
///
int inPixels(BufferView * bv) const;
- ///
- int inPixels(int default_height, int default_skip, int default_width=0) const;
private:
/// This VSpace kind
vspace_kind kind_;
Index: support/types.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/types.h,v
retrieving revision 1.2
diff -u -p -r1.2 types.h
--- support/types.h 2001/11/29 17:12:21 1.2
+++ support/types.h 2001/11/30 16:47:59
@@ -7,29 +7,29 @@
// this probably could be improved by using <cstddef>...
-#include <vector>
+#include <cstddef>
namespace lyx
{
/// a type for positions used in paragraphs
// needs to be signed for a while to hold the special value -1 that is
// used there...
- typedef std::vector<char>::difference_type pos_type;
+ typedef std::ptrdiff_t pos_type;
// set this to '0' if you want to have really safe types
#if 1
/// a type for sizes
- typedef std::vector<char>::size_type size_type;
+ typedef std::size_t size_type;
/// a type used for numbering layouts within a text class
// used to be LyXTextClass::size_type
- typedef std::vector<char>::size_type layout_type;
+ typedef std::size_t layout_type;
/// a type used for numbering text classes
// used to be LyXTextClassList::size_type
- typedef std::vector<char>::size_type textclass_type;
+ typedef std::size_t textclass_type;
#else
@@ -39,7 +39,7 @@ namespace lyx
struct size_type {
///
- typedef std::vector<char>::size_type base_type;
+ typedef std::size_t base_type;
///
size_type(base_type t) { data_ = t; }
///
@@ -52,7 +52,7 @@ namespace lyx
struct layout_type {
///
- typedef std::vector<char>::size_type base_type;
+ typedef std::size_t base_type;
///
layout_type(base_type t) { data_ = t; }
///