]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphicsParams.C
Added various inset functions for Jean-Marc (see Changelog). Small fix in
[lyx.git] / src / insets / insetgraphicsParams.C
index 8ac312521afeb2d3c5b36480955f44a27b7c78e7..0218ac1ddcdc6a1e2108181490417cf49713dab2 100644 (file)
@@ -1,10 +1,9 @@
-// -*- C++ -*-
 /* This file is part of
  * =================================================
  * 
  *          LyX, The Document Processor
  *          Copyright 1995 Matthias Ettrich.
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  *          This file Copyright 2000 Baruch Even
  * ================================================= */
 
 #include "support/LAssert.h"
 
-using std::endl;
+namespace {
 
 /// This variable keeps a tab on whether the translator was set with the
 /// translations.
-static bool translatorsSet = false;
+bool translatorsSet = false;
 
 /// This is the translator between the Resize enum and corresponding lyx
 /// file strings.
-static Translator < InsetGraphicsParams::Resize, string >
+Translator< InsetGraphicsParams::Resize, string >
 resizeTranslator(InsetGraphicsParams::DEFAULT_SIZE, "default");
 
 /// This is the translator between the Origin enum and corresponding lyx
 /// file strings.
-static Translator < InsetGraphicsParams::Origin, string >
+Translator< InsetGraphicsParams::Origin, string >
 originTranslator(InsetGraphicsParams::DEFAULT, "default");
 
 /// This is the translator between the Display enum and corresponding lyx
 /// file strings.
-static Translator < InsetGraphicsParams::DisplayType, string >
+Translator< InsetGraphicsParams::DisplayType, string >
 displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome");
 
+} // namespace anon
 
 
 InsetGraphicsParams::InsetGraphicsParams()
@@ -145,34 +145,34 @@ void InsetGraphicsParams::testInvariant() const
        // Filename might be empty (when the dialog is first created).
        // Assert(!filename.empty());
 
-       Assert(display == COLOR ||
+       lyx::Assert(display == COLOR ||
               display == MONOCHROME ||
               display == GRAYSCALE ||
               display == NONE
              );
 
-       Assert(widthResize == DEFAULT_SIZE ||
+       lyx::Assert(widthResize == DEFAULT_SIZE ||
               widthResize == CM ||
               widthResize == INCH ||
               widthResize == PERCENT_PAGE ||
               widthResize == PERCENT_COLUMN
              );
 
-       Assert(heightResize == DEFAULT_SIZE ||
+       lyx::Assert(heightResize == DEFAULT_SIZE ||
               heightResize == CM ||
               heightResize == INCH ||
               heightResize == PERCENT_PAGE
              );
 
-       Assert(widthSize >= 0.0);
-       Assert(heightSize >= 0.0);
+       lyx::Assert(widthSize >= 0.0);
+       lyx::Assert(heightSize >= 0.0);
 
        // Angle is in degrees and ranges -360 < angle < 360
        // The reason for this is that in latex there is a meaning for the
        // different angles and they are not necessarliy interchangeable,
        // it depends on the rotation origin.
-       Assert(rotateAngle < 360);
-       Assert(rotateAngle > -360);
+       lyx::Assert(rotateAngle < 360);
+       lyx::Assert(rotateAngle > -360);
 
 }
 
@@ -197,96 +197,33 @@ bool operator==(InsetGraphicsParams const & left,
        return false;
 }
 
+bool operator!=(InsetGraphicsParams const & left,
+                InsetGraphicsParams const & right)
+{
+       return  !(left == right);
+}
+
+
+namespace {
 
-static
 void writeResize(ostream & os, string const & key,
                         InsetGraphicsParams::Resize resize, double size)
 {
        os << ' ' << key << "Resize ";
 
        os << resizeTranslator.find(resize);
-#if 0
-       // Old code, before using translators
-       switch (resize) {
-       case InsetGraphicsParams::DEFAULT_SIZE:
-               os << "default";
-               break;
-
-       case InsetGraphicsParams::CM:
-               os << "cm";
-               break;
-
-       case InsetGraphicsParams::INCH:
-               os << "inch";
-               break;
-
-       case InsetGraphicsParams::PERCENT_PAGE:
-               os << "percentOfPage";
-               break;
-
-       case InsetGraphicsParams::PERCENT_COLUMN:
-               os << "percentOfColumnt";
-               break;
-       }
-#endif 
-       os << ' ' << key << ' ' << size << endl;
+       os << ' ' << key << ' ' << size << '\n';
 }
 
-static void writeOrigin(ostream & os,
+void writeOrigin(ostream & os,
                         InsetGraphicsParams::Origin origin)
 {
        os << " rotateOrigin " << originTranslator.find(origin);
+       os << '\n';
+}
 
-#if 0
-       // Old method.
-       switch (origin) {
-       case InsetGraphicsParams:: DEFAULT:
-               os << "default";
-               break;
-       case InsetGraphicsParams::      LEFTTOP:
-               os << "LeftTop";
-               break;
-       case InsetGraphicsParams::      LEFTCENTER:
-               os << "LeftCenter";
-               break;
-       case InsetGraphicsParams::      LEFTBASELINE:
-               os << "LeftBaseLine";
-               break;
-       case InsetGraphicsParams::      LEFTBOTTOM:
-               os << "LeftBottom";
-               break;
-       case InsetGraphicsParams::      CENTERTOP:
-               os << "CenterTop";
-               break;
-       case InsetGraphicsParams::      CENTER:
-               os << "Center";
-               break;
-       case InsetGraphicsParams::      CENTERBASELINE:
-               os << "CenterBaseLine";
-               break;
-       case InsetGraphicsParams::      CENTERBOTTOM:
-               os << "CenterBottom";
-               break;
-       case InsetGraphicsParams::      RIGHTTOP:
-               os << "RightTop";
-               break;
-       case InsetGraphicsParams::      RIGHTCENTER:
-               os << "RightCenter";
-               break;
-       case InsetGraphicsParams::      RIGHTBASELINE:
-               os << "RightBaseLine";
-               break;
-       case InsetGraphicsParams::      RIGHTBOTTOM:
-               os << "RightBottom";
-               break;
-               // Current REFERENCE_POINT is aliased to LEFTBASELINE
-               //    case InsetGraphicsParams::        REFERENCE_POINT:
-       }
-
-#endif 
+} // namespace anon
 
-       os << endl;
-}
 
 void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
 {
@@ -294,31 +231,11 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
        if (! filename.empty()) {
                os << "filename "
                << MakeRelPath(filename, OnlyPath(buf->fileName()))
-               << endl;
+               << '\n';
        }
 
        // Save the display type
-       os << " display " << displayTranslator.find(display) << endl;
-#if 0
-       switch (display) {
-       case COLOR:
-               os << "color";
-               break;
-
-       case GRAYSCALE:
-               os << "grayscale";
-               break;
-
-       case MONOCHROME:
-               os << "monochrome";
-               break;
-
-       case NONE:
-               os << "none";
-               break;
-       }
-       os << endl;
-#endif 
+       os << " display " << displayTranslator.find(display) << '\n';
 
        // Save the inline status
        if (inlineFigure)
@@ -329,39 +246,25 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
                os << " subcaption";
 
        if (! subcaptionText.empty())
-               os << " subcaptionText \"" << subcaptionText << '\"' << endl;
+               os << " subcaptionText \"" << subcaptionText << '\"' << '\n';
 
        writeResize(os, "width", widthResize, widthSize);
        writeResize(os, "height", heightResize, heightSize);
 
        writeOrigin(os, rotateOrigin);
        if (rotateAngle != 0)
-               os << " rotateAngle " << rotateAngle << endl;
+               os << " rotateAngle " << rotateAngle << '\n';
 }
 
-static void readResize(InsetGraphicsParams * igp, bool height,
+
+namespace {
+
+void readResize(InsetGraphicsParams * igp, bool height,
                        string const & token)
 {
        InsetGraphicsParams::Resize resize = InsetGraphicsParams::DEFAULT_SIZE;
 
        resize = resizeTranslator.find(token);
-#if 0
-       // Old code, before translator.
-       if (token == "default")
-               resize = InsetGraphicsParams::DEFAULT_SIZE;
-       else if (token == "cm")
-               resize = InsetGraphicsParams::CM;
-       else if (token == "inch")
-               resize = InsetGraphicsParams::INCH;
-       else if (token == "percentOfPage")
-               resize = InsetGraphicsParams::PERCENT_PAGE;
-       else if (token == "percentOfColumn")
-               resize = InsetGraphicsParams::PERCENT_COLUMN;
-       else {
-               lyxerr << "BUG: When reading resize value of InsetGraphicsParam"
-               " unknown token found '" << token << '\'' << endl;
-       }
-#endif 
 
        if (height)
                igp->heightResize = resize;
@@ -369,11 +272,16 @@ static void readResize(InsetGraphicsParams * igp, bool height,
                igp->widthResize = resize;
 }
 
-static void readOrigin(InsetGraphicsParams * igp, string const & token)
-{ // TODO: complete this function.
+
+void readOrigin(InsetGraphicsParams * igp, string const & token)
+{
+       // TODO: complete this function.
        igp->rotateOrigin = originTranslator.find(token);
 }
 
+} // namespace anon
+
+
 bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex,
                                string const& token)
 {
@@ -390,21 +298,6 @@ bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex,
                string const type = lex.GetString();
 
                display = displayTranslator.find(type);
-#if 0
-               if (type == "color")
-                       display = COLOR;
-               else if (type == "grayscale")
-                       display = GRAYSCALE;
-               else if (type == "monochrome")
-                       display = MONOCHROME;
-               else if (type == "none")
-                       display = NONE;
-               else {
-                       display = MONOCHROME;
-                       lyxerr << "BUG: When reading InsetGraphicsParams"
-                       " display has an unknown type " << type << endl;
-               }
-#endif 
        } else if (token == "inline") {
                inlineFigure = true;
        } else if (token == "subcaption") {