]> git.lyx.org Git - lyx.git/blobdiff - src/vspace.C
the buffer patch, moved Buffer::text to BufferView, moved Buffer::update(short) to...
[lyx.git] / src / vspace.C
index d442fa9794810facf772fcc8bea9c51d574e5ecb..f80632bc546ba3475a373a465b812be94325ec00 100644 (file)
@@ -1,13 +1,13 @@
 // -*- C++ -*-
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
  *          Copyright 1995-1999 The LyX Team.
  *
- * ======================================================*/
+ * ====================================================== */
 
 #include <config.h>
 
@@ -31,7 +31,7 @@ extern BufferView *current_view;
 /*  length units
  */
 
-static const int   num_units            = int(LyXLength::UNIT_NONE);
+static const int   num_units            = LyXLength::UNIT_NONE;
 
 // I am not sure if "mu" should be possible to select (Lgb)
 static char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
@@ -41,7 +41,7 @@ static char const * unit_name[num_units] = { "sp", "pt", "bp", "dd",
 
 LyXLength::UNIT unitFromString (string const & data)
 {
-       int i=0;
+       int i = 0;
        while ((i<num_units) && (data != unit_name[i])) ++i;
        return (LyXLength::UNIT)i;
 }
@@ -57,7 +57,7 @@ static LyXLength::UNIT unit[4]   = { LyXLength::UNIT_NONE,
 //static int number_index, unit_index;
 int number_index, unit_index;
 
-static inline void advance (string & data, unsigned int n)
+static inline void lyx_advance (string & data, unsigned int n)
 {
        data.erase(0, n);
 }
@@ -73,42 +73,42 @@ static char nextToken (string & data)
        if (data.empty())
                return '\0';
        else if (data[0] == '+') {
-               advance (data, 1);
+               lyx_advance (data, 1);
                return '+';
        }
        else if (prefixIs(data, "plus")) {
-               advance (data, 4);
+               lyx_advance (data, 4);
                return '+';
        }
        else if (data[0] == '-') {
-               advance (data, 1);
+               lyx_advance (data, 1);
                return '-';
        }
         else if (prefixIs(data, "minus")) {
-               advance (data, 5);
+               lyx_advance (data, 5);
                return '-';
        }
        else {
                string::size_type i;
 
                // I really mean assignment ("=") below, not equality!
-               if ((i = data.find_first_not_of("0123456789.")) != string::npos) {
+               if ((i = data.find_last_of("0123456789.")) != string::npos) {
                        if (number_index > 3) return 'E';  // Error
-                        string buffer = data.substr(0, i);
+                        string buffer = data.substr(0, i + 1);
                        if (sscanf (buffer.c_str(),
                                    "%f", &number[number_index]) == 1) {
-                               advance (data, i);
+                               lyx_advance (data, i + 1);
                                ++number_index;
                                return 'n';
                        } else 
                                return 'E';  // Error
-               } else if (( i = data
-                            .find_first_of("abcdefghijklmnopqrstuvwxyz")) != string::npos) {
+               } else if ((i = data.find_last_of("abcdefghijklmnopqrstuvwxyz"))
+                          != string::npos) {
                        if (unit_index > 3) return 'E';  // Error
-                       string buffer = data.substr(0, i);
+                       string buffer = data.substr(0, i + 1);
                        unit[unit_index] = unitFromString (buffer);
                        if (unit[unit_index] != LyXLength::UNIT_NONE) {
-                               advance (data, i);
+                               lyx_advance (data, i + 1);
                                ++unit_index;
                                return 'u';
                        } else
@@ -165,11 +165,11 @@ bool isValidGlueLength (string const & data, LyXGlueLength * result)
        short val_sign = 1; // positive as default
        switch(buffer[0]) {
        case '-':
-               advance(buffer, 1);
+               lyx_advance(buffer, 1);
                val_sign = -1;
                break;
        case '+':
-               advance(buffer, 1);
+               lyx_advance(buffer, 1);
                // fall through
        default:
                // no action
@@ -229,11 +229,11 @@ bool isValidLength(string const & data, LyXLength * result)
        short val_sign = 1; // positive as default
        switch(buffer[0]) {
        case '-':
-               advance(buffer, 1);
+               lyx_advance(buffer, 1);
                val_sign = -1;
                break;
        case '+':
-               advance(buffer, 1);
+               lyx_advance(buffer, 1);
                // fall through
        default:
                // no action
@@ -303,12 +303,12 @@ LyXGlueLength::LyXGlueLength (string const & data)
        if (!isValidGlueLength (data, &tmp))
                return; // should raise an exception
        else {
-               val=tmp.val;
-               uni=tmp.uni;
-               plus_val =tmp.plus_val;
-               plus_uni =tmp.plus_uni;
-               minus_val=tmp.minus_val;
-               minus_uni=tmp.minus_uni;
+               val = tmp.val;
+               uni = tmp.uni;
+               plus_val = tmp.plus_val;
+               plus_uni = tmp.plus_uni;
+               minus_val = tmp.minus_val;
+               minus_uni = tmp.minus_uni;
        }
 }
 
@@ -433,7 +433,7 @@ VSpace::VSpace (string const & data)
 }
 
 
-bool VSpace::operator== (VSpace const & other) const
+bool VSpace::operator==(VSpace const & other) const
 {
        if (this->kin == other.kin) 
                if (this->kin == LENGTH)
@@ -473,7 +473,7 @@ string VSpace::asLatexCommand() const
        switch (kin) {
        case NONE:      return string();
        case DEFSKIP:   
-         return current_view->currentBuffer()->params.getDefSkip().asLatexCommand();
+         return current_view->buffer()->params.getDefSkip().asLatexCommand();
        case SMALLSKIP: return kp ? "\\vspace*{\\smallskipamount}"
                                  : "\\smallskip{}";
        case MEDSKIP:   return kp ? "\\vspace*{\\medskipamount}"
@@ -492,7 +492,11 @@ string VSpace::asLatexCommand() const
 int VSpace::inPixels() const
 {
        // Height of a normal line in pixels (zoom factor considered)
-       int height = current_view->currentBuffer()->text->DefaultHeight(); // [pixels]
+#ifdef MOVE_TEXT
+       int height = current_view->text->DefaultHeight(); // [pixels]
+#else
+       int height = current_view->buffer()->text->DefaultHeight(); // [pixels]
+#endif
 
        // Zoom factor specified by user in percent
        float const zoom = lyxrc->zoom / 100.0; // [percent]
@@ -507,7 +511,7 @@ int VSpace::inPixels() const
        case NONE: return 0;
 
        case DEFSKIP:
-         return current_view->currentBuffer()->params.getDefSkip().inPixels();
+         return current_view->buffer()->params.getDefSkip().inPixels();
 
        // This is how the skips are normally defined by
        // LateX.  But there should be some way to change