]> git.lyx.org Git - lyx.git/blobdiff - src/LColor.C
tostr -> convert and some bformat work
[lyx.git] / src / LColor.C
index 96e11cad0d54ff69562960f28ae42f6969e98fc9..b2f1ba545fb5cc54cacea464eac6d175d36df273 100644 (file)
@@ -24,6 +24,7 @@
 #include <map>
 
 using lyx::support::compare_ascii_no_case;
+using lyx::support::ascii_lowercase;
 
 using std::endl;
 using std::string;
@@ -159,10 +160,10 @@ LColor::~LColor()
 {}
 
 
-void LColor::operator=(LColor const & c)
+LColor & LColor::operator=(LColor tmp)
 {
-       LColor tmp(c);
        boost::swap(pimpl_, tmp.pimpl_);
+       return *this;
 }
 
 
@@ -222,12 +223,27 @@ bool LColor::setColor(LColor::color col, string const & x11name)
                       << " may not be redefined" << endl;
                return false;
        }
-       
+
        it->second.x11name = x11name;
        return true;
 }
 
 
+bool LColor::setColor(string const & lyxname, string const &x11name)
+{
+       string const lcname = ascii_lowercase(lyxname);
+       if (pimpl_->transform.find(lcname) == pimpl_->transform.end()) {
+               lyxerr[Debug::GUI]
+                       << "LColor::setColor: Unknown color \""
+                      << lyxname << '"' << endl;
+               addColor(static_cast<color>(pimpl_->infotab.size()), lcname);
+       }
+
+       return setColor(static_cast<LColor::color>(pimpl_->transform[lcname]),
+                       x11name);
+}
+
+
 LColor::color LColor::getFromGUIName(string const & guiname) const
 {
        Pimpl::InfoTab::const_iterator it = pimpl_->infotab.begin();
@@ -249,10 +265,14 @@ void LColor::addColor(LColor::color c, string const & lyxname) const
 
 LColor::color LColor::getFromLyXName(string const & lyxname) const
 {
-       if (pimpl_->transform.find(lyxname) == pimpl_->transform.end())
-               addColor(static_cast<color>(pimpl_->infotab.size()), lyxname);
+       string const lcname = ascii_lowercase(lyxname);
+       if (pimpl_->transform.find(lcname) == pimpl_->transform.end()) {
+               lyxerr << "LColor::getFromLyXName: Unknown color \""
+                      << lyxname << '"' << endl;
+               return none;
+       }
 
-       return static_cast<LColor::color>(pimpl_->transform[lyxname]);
+       return static_cast<LColor::color>(pimpl_->transform[lcname]);
 }