]> git.lyx.org Git - lyx.git/blobdiff - src/lyxlength.C
John's Layout Tabular UI improvements and Martins fixes to clearing the
[lyx.git] / src / lyxlength.C
index 8f782873bc361eaafaad98e26ee6c65500aeb139..c1e08dd4448746a8036f8495098470712d3a351c 100644 (file)
 #endif
 
 #include "lyxlength.h"
+#include "lengthcommon.h"
 
 #include "Lsstream.h"
 
-namespace {
-// this is now here and in lyxgluelength.C
-
-int const num_units = LyXLength::UNIT_NONE;
-
-// I am not sure if "mu" should be possible to select (Lgb)
-char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
-                                     "mm", "pc", "cc", "cm",
-                                     "in", "ex", "em", "mu",
-                                     "%",  "c%", "p%", "l%" };
-
-
-LyXLength::UNIT unitFromString(string const & data)
-{
-       int i = 0;
-       while (i < num_units && data != unit_name[i])
-               ++i;
-       return static_cast<LyXLength::UNIT>(i);
-}
-
-}
+#include <cstdlib>
 
 
 LyXLength::LyXLength()
@@ -52,6 +33,7 @@ LyXLength::LyXLength(double v, LyXLength::UNIT u)
 
 
 LyXLength::LyXLength(string const & data)
+       : val_(0), unit_(LyXLength::PT)
 {
        LyXLength tmp;
        
@@ -78,15 +60,15 @@ string const LyXLength::asLatexString() const
        case PW:
        case PE:
            buffer << abs(static_cast<int>(val_/100)) << "."
-                               << abs(static_cast<int>(val_)%100) << "\\columnwidth";
+                  << abs(static_cast<int>(val_)%100) << "\\columnwidth";
            break;
        case PP:
            buffer << abs(static_cast<int>(val_/100)) << "."
-                               << abs(static_cast<int>(val_)%100) << "\\pagewidth";
+                  << abs(static_cast<int>(val_)%100) << "\\pagewidth";
            break;
        case PL:
            buffer << abs(static_cast<int>(val_/100)) << "."
-                               << abs(static_cast<int>(val_)%100) << "\\linewidth";
+                  << abs(static_cast<int>(val_)%100) << "\\linewidth";
            break;
        default:
            buffer << val_ << unit_name[unit_]; // setw?
@@ -120,7 +102,20 @@ void LyXLength::unit(LyXLength::UNIT u)
 }
 
 
+bool LyXLength::zero() const 
+{
+       return val_ == 0.0;
+}
+
+
 bool operator==(LyXLength const & l1, LyXLength const & l2)
 {
        return l1.value() == l2.value() && l1.unit() == l2.unit();
 }
+
+
+bool operator!=(LyXLength const & l1, LyXLength const & l2)
+{
+       return !(l1 == l2);
+}
+