]> git.lyx.org Git - lyx.git/blobdiff - src/LColor.C
ws changes only
[lyx.git] / src / LColor.C
index a36d1a7d8328b82835e8f3b63366176957e4c722..ba42c4b761f01f5481ba5cbff244a6c4df003351 100644 (file)
@@ -1,31 +1,38 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file LColor.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Matthias Ettrich
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ * \author André Pönitz
+ * \author Martin Vermeer
  *
- *         Copyright 1998-2001 The LyX Team
- *
- *======================================================*/
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "debug.h"
-#include "LColor.h"
-#include "support/LAssert.h"
 #include "gettext.h"
+#include "LColor.h"
 #include "support/lstrings.h"
 
 #include <map>
 
-using namespace lyx::support;
+using lyx::support::compare_ascii_no_case;
 
 using std::endl;
+using std::string;
 
 
 namespace {
 
 struct ColorEntry {
-       LColor::color lcolor;
+       int lcolor;
        char const * guiname;
        char const * latexname;
        char const * x11name;
@@ -34,6 +41,11 @@ struct ColorEntry {
 
 }
 
+struct TransformEntry {
+       char const * lyxname;
+       int ncolor;
+};
+
 
 struct LColor::Pimpl {
        ///
@@ -51,17 +63,24 @@ struct LColor::Pimpl {
        /// initialise a color entry
        void fill(ColorEntry const & entry)
        {
-               information & in = infotab[entry.lcolor];
-               in.guiname   = entry.guiname;
-               in.latexname = entry.latexname;
-               in.x11name   = entry.x11name;
-               in.lyxname   = entry.lyxname;
+               information in;
+               in.lyxname   = string(entry.lyxname);
+               in.latexname = string(entry.latexname);
+               in.x11name   = string(entry.x11name);
+               in.guiname   = string(entry.guiname);
+               infotab[entry.lcolor] = in;
+               transform[string(entry.lyxname)] = int(entry.lcolor);
        }
 
        ///
-       typedef std::map<LColor::color, information> InfoTab;
+       typedef std::map<int, information> InfoTab;
        /// the table of color information
        InfoTab infotab;
+
+       typedef std::map<string, int> Transform;
+       /// the transform between colour name string and integer code.
+       Transform transform;
+
 };
 
 
@@ -143,18 +162,31 @@ LColor::LColor(LColor const & c)
 
 
 LColor::~LColor()
-{
-       delete pimpl_;
-}
+{}
 
 
 void LColor::operator=(LColor const & c)
 {
        LColor tmp(c);
-       std::swap(pimpl_, tmp.pimpl_);
+       boost::swap(pimpl_, tmp.pimpl_);
 }
 
 
+void LColor::fill(LColor::color c,
+                               string const & lyxname,
+                               string const & x11name,
+                               string const & latexname,
+                               string const & guiname)
+{
+       ColorEntry ce;
+       ce.lcolor = c;
+       ce.guiname = guiname.c_str();
+       ce.latexname = latexname.c_str();
+       ce.x11name = x11name.c_str();
+       ce.lyxname = lyxname.c_str();
+       pimpl_->fill(ce);
+}
+
 
 string const LColor::getGUIName(LColor::color c) const
 {
@@ -165,6 +197,19 @@ string const LColor::getGUIName(LColor::color c) const
 }
 
 
+string const LColor::getGUIName(string const &  s) const
+{
+       Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
+       if (ici != pimpl_->transform.end()) {
+               Pimpl::InfoTab::const_iterator
+                       it = pimpl_->infotab.find(ici->second);
+               if (it != pimpl_->infotab.end())
+                       return it->second.guiname;
+       }
+       return "none";
+}
+
+
 string const LColor::getX11Name(LColor::color c) const
 {
        Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
@@ -178,6 +223,22 @@ string const LColor::getX11Name(LColor::color c) const
 }
 
 
+string const LColor::getX11Name(string const & s) const
+{
+       Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
+       if (ici != pimpl_->transform.end()) {
+               Pimpl::InfoTab::const_iterator
+                       it = pimpl_->infotab.find(ici->second);
+               if (it != pimpl_->infotab.end())
+                       return it->second.x11name;
+       }
+       lyxerr << "LyX internal error: Missing color"
+               " entry in LColor.C for " << s << endl;
+       lyxerr << "Using black." << endl;
+       return "black";
+}
+
+
 string const LColor::getLaTeXName(LColor::color c) const
 {
        Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
@@ -187,6 +248,19 @@ string const LColor::getLaTeXName(LColor::color c) const
 }
 
 
+string const LColor::getLaTeXName(string const & s) const
+{
+       Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s);
+       if (ici != pimpl_->transform.end()) {
+               Pimpl::InfoTab::const_iterator
+                       it = pimpl_->infotab.find(ici->second);
+               if (it != pimpl_->infotab.end())
+                       return it->second.latexname;
+       }
+       return "black";
+}
+
+
 string const LColor::getLyXName(LColor::color c) const
 {
        Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c);
@@ -196,6 +270,12 @@ string const LColor::getLyXName(LColor::color c) const
 }
 
 
+size_t LColor::size() const
+{
+       return pimpl_->infotab.size();
+}
+
+
 void LColor::setColor(LColor::color col, string const & x11name)
 {
        Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col);
@@ -204,7 +284,7 @@ void LColor::setColor(LColor::color col, string const & x11name)
                return;
        }
        lyxerr << "LyX internal error: color and such." << endl;
-       Assert(false);
+       BOOST_ASSERT(false);
 }
 
 
@@ -219,7 +299,7 @@ bool LColor::setColor(string const & lyxname, string const & x11name)
                        " redefined" << endl;
                return false;
        }
-       setColor (col, x11name);
+       setColor(col, x11name);
        return true;
 }
 
@@ -230,7 +310,7 @@ LColor::color LColor::getFromGUIName(string const & guiname) const
        Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
        for (; ici != end; ++ici) {
                if (!compare_ascii_no_case(_(ici->second.guiname), guiname))
-                       return ici->first;
+                       return static_cast<LColor::color>(ici->first);
        }
        return LColor::inherit;
 }
@@ -238,13 +318,7 @@ LColor::color LColor::getFromGUIName(string const & guiname) const
 
 LColor::color LColor::getFromLyXName(string const & lyxname) const
 {
-       Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin();
-       Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end();
-       for (; ici != end; ++ici) {
-               if (!compare_ascii_no_case(ici->second.lyxname, lyxname))
-                       return ici->first;
-       }
-       return LColor::inherit;
+       return static_cast<LColor::color>(pimpl_->transform[lyxname]);
 }