]> git.lyx.org Git - lyx.git/blobdiff - src/LColor.C
Point fix, earlier forgotten
[lyx.git] / src / LColor.C
index aa81477110d1fca4b415b4af3191330116ef227b..b5aeb412cc10e6c1120b4c364367da8a31c64e3d 100644 (file)
@@ -1,11 +1,18 @@
-/* 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 <map>
 
+using namespace lyx::support;
+
 using std::endl;
 
 
 namespace {
 
 struct ColorEntry {
-       LColor::color lcolor;
+       int lcolor;
        char const * guiname;
        char const * latexname;
        char const * x11name;
@@ -32,6 +41,11 @@ struct ColorEntry {
 
 }
 
+struct TransformEntry {
+       char const * lyxname;
+       int ncolor;
+};
+
 
 struct LColor::Pimpl {
        ///
@@ -49,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;
+
 };
 
 
@@ -85,6 +106,10 @@ LColor::LColor()
        { preview, N_("previewed snippet"), "preview", "black", "preview" },
        { note, N_("note"), "note", "yellow", "note" },
        { notebg, N_("note background"), "notebg", "yellow", "notebg" },
+       { comment, N_("comment"), "comment", "magenta", "comment" },
+       { commentbg, N_("comment background"), "commentbg", "linen", "commentbg" },
+       { greyedout, N_("greyedout inset"), "greyedout", "red", "greyedout" },
+       { greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" },
        { depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
        { language, N_("language"), "language", "Blue", "language" },
        { command, N_("command inset"), "command", "black", "command" },
@@ -137,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
 {
@@ -159,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);
@@ -166,8 +217,24 @@ string const LColor::getX11Name(LColor::color c) const
                return ici->second.x11name;
 
        lyxerr << "LyX internal error: Missing color"
-               " entry in LColor.C for " << int(c) << '\n';
-       lyxerr << "Using black.\n";
+               " entry in LColor.C for " << int(c) << endl;
+       lyxerr << "Using black." << endl;
+       return "black";
+}
+
+
+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";
 }
 
@@ -181,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);
@@ -190,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);
@@ -197,8 +283,8 @@ void LColor::setColor(LColor::color col, string const & x11name)
                iti->second.x11name = x11name;
                return;
        }
-       lyxerr << "LyX internal error: color and such.\n";
-       lyx::Assert(false);
+       lyxerr << "LyX internal error: color and such." << endl;
+       Assert(false);
 }
 
 
@@ -213,7 +299,7 @@ bool LColor::setColor(string const & lyxname, string const & x11name)
                        " redefined" << endl;
                return false;
        }
-       setColor (col, x11name);
+       setColor(col, x11name);
        return true;
 }
 
@@ -224,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;
 }
@@ -232,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]);
 }