pimpl not needed here

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21395 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-02 23:42:27 +00:00
parent ebd2089bc2
commit 09df753df4
14 changed files with 141 additions and 178 deletions

View File

@ -11,6 +11,7 @@
#include <config.h> #include <config.h>
#include "BranchList.h" #include "BranchList.h"
#include "Color.h"
#include "frontends/Application.h" #include "frontends/Application.h"
@ -68,10 +69,10 @@ void Branch::setColor(RGBColor const & c)
} }
void Branch::setColor(string const & c) void Branch::setColor(string const & str)
{ {
if (c.size() == 7 && c[0] == '#') if (str.size() == 7 && str[0] == '#')
color_ = RGBColor(c); color_ = rgbFromHexName(str);
else else
// no color set or invalid color - use normal background // no color set or invalid color - use normal background
theApp()->getRgbColor(Color_background, color_); theApp()->getRgbColor(Color_background, color_);

View File

@ -30,7 +30,7 @@
#ifndef BRANCHES_H #ifndef BRANCHES_H
#define BRANCHES_H #define BRANCHES_H
#include "Color.h" #include "ColorCode.h"
#include "support/docstring.h" #include "support/docstring.h"

View File

@ -21,6 +21,7 @@
#include "BranchList.h" #include "BranchList.h"
#include "buffer_funcs.h" #include "buffer_funcs.h"
#include "Bullet.h" #include "Bullet.h"
#include "Color.h"
#include "debug.h" #include "debug.h"
#include "Encoding.h" #include "Encoding.h"
#include "gettext.h" #include "gettext.h"

View File

@ -16,12 +16,15 @@
#include <config.h> #include <config.h>
#include "debug.h"
#include "gettext.h"
#include "Color.h" #include "Color.h"
#include "debug.h"
#include "gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <boost/assert.hpp>
#include <map> #include <map>
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
@ -46,9 +49,7 @@ namespace lyx {
using support::compare_ascii_no_case; using support::compare_ascii_no_case;
using support::ascii_lowercase; using support::ascii_lowercase;
namespace { struct ColorSet::ColorEntry {
struct ColorEntry {
ColorCode lcolor; ColorCode lcolor;
char const * guiname; char const * guiname;
char const * latexname; char const * latexname;
@ -56,9 +57,8 @@ struct ColorEntry {
char const * lyxname; char const * lyxname;
}; };
int const nohue = -1;
int hexstrToInt(string const & str) static int hexstrToInt(string const & str)
{ {
int val = 0; int val = 0;
istringstream is(str); istringstream is(str);
@ -66,8 +66,6 @@ int hexstrToInt(string const & str)
return val; return val;
} }
} // namespace anon
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// //
@ -89,66 +87,18 @@ string const X11hexname(RGBColor const & col)
} }
RGBColor::RGBColor(string const & x11hexname) RGBColor rgbFromHexName(string const & x11hexname)
: r(0), g(0), b(0)
{ {
RGBColor c;
BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#'); BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
r = hexstrToInt(x11hexname.substr(1,2)); c.r = hexstrToInt(x11hexname.substr(1,2));
g = hexstrToInt(x11hexname.substr(3,2)); c.g = hexstrToInt(x11hexname.substr(3,2));
b = hexstrToInt(x11hexname.substr(5,2)); c.b = hexstrToInt(x11hexname.substr(5,2));
return c;
} }
///////////////////////////////////////////////////////////////////// ColorSet::ColorSet()
//
// Color::Pimpl
//
/////////////////////////////////////////////////////////////////////
class Color::Pimpl {
public:
///
class information {
public:
/// the name as it appears in the GUI
string guiname;
/// the name used in LaTeX
string latexname;
/// the name for X11
string x11name;
/// the name for LyX
string lyxname;
};
/// initialise a color entry
void fill(ColorEntry const & entry)
{
information in;
in.lyxname = entry.lyxname;
in.latexname = entry.latexname;
in.x11name = entry.x11name;
in.guiname = entry.guiname;
infotab[entry.lcolor] = in;
lyxcolors[entry.lyxname] = entry.lcolor;
latexcolors[entry.latexname] = entry.lcolor;
}
///
typedef std::map<ColorCode, information> InfoTab;
/// the table of color information
InfoTab infotab;
typedef std::map<string, ColorCode> Transform;
/// the transform between LyX color name string and integer code.
Transform lyxcolors;
/// the transform between LaTeX color name string and integer code.
Transform latexcolors;
};
Color::Color()
: pimpl_(new Pimpl)
{ {
// ColorCode, gui, latex, x11, lyx // ColorCode, gui, latex, x11, lyx
static ColorEntry const items[] = { static ColorEntry const items[] = {
@ -219,39 +169,37 @@ Color::Color()
}; };
for (int i = 0; items[i].guiname; ++i) for (int i = 0; items[i].guiname; ++i)
pimpl_->fill(items[i]); fill(items[i]);
} }
Color::Color(Color const & c) /// initialise a color entry
: pimpl_(new Pimpl(*c.pimpl_)) void ColorSet::fill(ColorEntry const & entry)
{}
Color::~Color()
{}
Color & Color::operator=(Color tmp)
{ {
boost::swap(pimpl_, tmp.pimpl_); Information in;
return *this; in.lyxname = entry.lyxname;
in.latexname = entry.latexname;
in.x11name = entry.x11name;
in.guiname = entry.guiname;
infotab[entry.lcolor] = in;
lyxcolors[entry.lyxname] = entry.lcolor;
latexcolors[entry.latexname] = entry.lcolor;
} }
docstring const Color::getGUIName(ColorCode c) const docstring const ColorSet::getGUIName(ColorCode c) const
{ {
Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c); InfoTab::const_iterator it = infotab.find(c);
if (it != pimpl_->infotab.end()) if (it != infotab.end())
return _(it->second.guiname); return _(it->second.guiname);
return from_ascii("none"); return from_ascii("none");
} }
string const Color::getX11Name(ColorCode c) const string const ColorSet::getX11Name(ColorCode c) const
{ {
Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c); InfoTab::const_iterator it = infotab.find(c);
if (it != pimpl_->infotab.end()) if (it != infotab.end())
return it->second.x11name; return it->second.x11name;
lyxerr << "LyX internal error: Missing color" lyxerr << "LyX internal error: Missing color"
@ -261,28 +209,28 @@ string const Color::getX11Name(ColorCode c) const
} }
string const Color::getLaTeXName(ColorCode c) const string const ColorSet::getLaTeXName(ColorCode c) const
{ {
Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c); InfoTab::const_iterator it = infotab.find(c);
if (it != pimpl_->infotab.end()) if (it != infotab.end())
return it->second.latexname; return it->second.latexname;
return "black"; return "black";
} }
string const Color::getLyXName(ColorCode c) const string const ColorSet::getLyXName(ColorCode c) const
{ {
Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c); InfoTab::const_iterator it = infotab.find(c);
if (it != pimpl_->infotab.end()) if (it != infotab.end())
return it->second.lyxname; return it->second.lyxname;
return "black"; return "black";
} }
bool Color::setColor(ColorCode col, string const & x11name) bool ColorSet::setColor(ColorCode col, string const & x11name)
{ {
Pimpl::InfoTab::iterator it = pimpl_->infotab.find(col); InfoTab::iterator it = infotab.find(col);
if (it == pimpl_->infotab.end()) { if (it == infotab.end()) {
lyxerr << "Color " << col << " not found in database." lyxerr << "Color " << col << " not found in database."
<< std::endl; << std::endl;
return false; return false;
@ -301,56 +249,58 @@ bool Color::setColor(ColorCode col, string const & x11name)
} }
bool Color::setColor(string const & lyxname, string const &x11name) bool ColorSet::setColor(string const & lyxname, string const &x11name)
{ {
string const lcname = ascii_lowercase(lyxname); string const lcname = ascii_lowercase(lyxname);
if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) { if (lyxcolors.find(lcname) == lyxcolors.end()) {
LYXERR(Debug::GUI) LYXERR(Debug::GUI)
<< "Color::setColor: Unknown color \"" << "ColorSet::setColor: Unknown color \""
<< lyxname << '"' << endl; << lyxname << '"' << endl;
addColor(static_cast<ColorCode>(pimpl_->infotab.size()), lcname); addColor(static_cast<ColorCode>(infotab.size()), lcname);
} }
return setColor(pimpl_->lyxcolors[lcname], x11name); return setColor(lyxcolors[lcname], x11name);
} }
void Color::addColor(ColorCode c, string const & lyxname) const void ColorSet::addColor(ColorCode c, string const & lyxname)
{ {
ColorEntry ce = { c, "", "", "", lyxname.c_str() }; ColorEntry ce = { c, "", "", "", lyxname.c_str() };
pimpl_->fill(ce); fill(ce);
} }
ColorCode Color::getFromLyXName(string const & lyxname) const ColorCode ColorSet::getFromLyXName(string const & lyxname) const
{ {
string const lcname = ascii_lowercase(lyxname); string const lcname = ascii_lowercase(lyxname);
if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) { Transform::const_iterator it = lyxcolors.find(lcname);
lyxerr << "Color::getFromLyXName: Unknown color \"" if (it == lyxcolors.end()) {
lyxerr << "ColorSet::getFromLyXName: Unknown color \""
<< lyxname << '"' << endl; << lyxname << '"' << endl;
return Color_none; return Color_none;
} }
return pimpl_->lyxcolors[lcname]; return it->second;
} }
ColorCode Color::getFromLaTeXName(string const & latexname) const ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
{ {
if (pimpl_->latexcolors.find(latexname) == pimpl_->latexcolors.end()) { Transform::const_iterator it = latexcolors.find(latexname);
lyxerr << "Color::getFromLaTeXName: Unknown color \"" if (it == latexcolors.end()) {
lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
<< latexname << '"' << endl; << latexname << '"' << endl;
return Color_none; return Color_none;
} }
return pimpl_->latexcolors[latexname]; return it->second;
} }
// The evil global Color instance // The evil global Color instance
Color lcolor; ColorSet lcolor;
// An equally evil global system Color instance // An equally evil global system Color instance
Color system_lcolor; ColorSet system_lcolor;
} // namespace lyx } // namespace lyx

View File

@ -23,19 +23,13 @@
#include "support/strfwd.h" #include "support/strfwd.h"
#include <boost/scoped_ptr.hpp> #include <map>
#include <string>
namespace lyx { namespace lyx {
/** /**
* This is a stateless class. * \class ColorSet
*
* It has one basic purposes:
* To serve as a color-namespace container (the Color enum).
*/
/**
* \class Color
* *
* A class holding color definitions and associated names for * A class holding color definitions and associated names for
* LaTeX, X11, the GUI, and LyX internally. * LaTeX, X11, the GUI, and LyX internally.
@ -46,19 +40,15 @@ namespace lyx {
* - A logical color, such as no color, inherit, math * - A logical color, such as no color, inherit, math
*/ */
class Color
// made copyable for same reasons as LyXRC was made copyable. See there for // made copyable for same reasons as LyXRC was made copyable. See there for
// explanation. // explanation.
class ColorSet
{ {
public: public:
/// ///
Color(); ColorSet();
///
Color(Color const &);
///
~Color();
///
Color & operator=(Color);
/** set the given LyX color to the color defined by the X11 name given /** set the given LyX color to the color defined by the X11 name given
* \returns true if successful. * \returns true if successful.
@ -87,48 +77,47 @@ public:
ColorCode getFromLyXName(std::string const & lyxname) const; ColorCode getFromLyXName(std::string const & lyxname) const;
/// \returns the ColorCode associated with the LaTeX name. /// \returns the ColorCode associated with the LaTeX name.
ColorCode getFromLaTeXName(std::string const & latexname) const; ColorCode getFromLaTeXName(std::string const & latexname) const;
private: private:
/// ///
void addColor(ColorCode c, std::string const & lyxname) const; void addColor(ColorCode c, std::string const & lyxname);
/// ///
class Pimpl; class Information {
public:
/// the name as it appears in the GUI
std::string guiname;
/// the name used in LaTeX
std::string latexname;
/// the name for X11
std::string x11name;
/// the name for LyX
std::string lyxname;
};
/// initialise a color entry
struct ColorEntry;
void fill(ColorEntry const & entry);
/// ///
boost::scoped_ptr<Pimpl> pimpl_; typedef std::map<ColorCode, Information> InfoTab;
/// the table of color Information
InfoTab infotab;
typedef std::map<std::string, ColorCode> Transform;
/// the transform between LyX color name string and integer code.
Transform lyxcolors;
/// the transform between LaTeX color name string and integer code.
Transform latexcolors;
}; };
/// the current color definitions /// the current color definitions
extern Color lcolor; extern ColorSet lcolor;
/// the system color definitions /// the system color definitions
extern Color system_lcolor; extern ColorSet system_lcolor;
struct RGBColor {
unsigned int r;
unsigned int g;
unsigned int b;
RGBColor() : r(0), g(0), b(0) {}
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
: r(red), g(green), b(blue) {}
/// \param x11hexname is of the form "#ffa071"
RGBColor(std::string const & x11hexname);
};
inline
bool operator==(RGBColor const & c1, RGBColor const & c2)
{
return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
}
inline
bool operator!=(RGBColor const & c1, RGBColor const & c2)
{
return !(c1 == c2);
}
/// returns a string of form #rrggbb, given an RGBColor struct
std::string const X11hexname(RGBColor const & col); std::string const X11hexname(RGBColor const & col);
RGBColor rgbFromHexName(std::string const & x11hexname);
} // namespace lyx } // namespace lyx

View File

@ -156,6 +156,27 @@ enum ColorCode
Color_ignore Color_ignore
}; };
struct RGBColor {
unsigned int r;
unsigned int g;
unsigned int b;
RGBColor() : r(0), g(0), b(0) {}
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
: r(red), g(green), b(blue) {}
};
inline bool operator==(RGBColor const & c1, RGBColor const & c2)
{
return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
}
inline bool operator!=(RGBColor const & c1, RGBColor const & c2)
{
return !(c1 == c2);
}
} // namespace lyx } // namespace lyx
#endif #endif

View File

@ -512,7 +512,7 @@ string const LaTeXFeatures::getPackages() const
} }
// shadecolor for shaded // shadecolor for shaded
if (mustProvide("framed") && mustProvide("color")) { if (mustProvide("framed") && mustProvide("color")) {
RGBColor c = RGBColor(lcolor.getX11Name(Color_shadedbg)); RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg));
//255.0 to force conversion to double //255.0 to force conversion to double
//NOTE As Jürgen Spitzmüller pointed out, an alternative would be //NOTE As Jürgen Spitzmüller pointed out, an alternative would be
//to use the xcolor package instead, and then we can do //to use the xcolor package instead, and then we can do
@ -616,9 +616,8 @@ string const LaTeXFeatures::getMacros() const
macros << '\n'; macros << '\n';
FeaturesList::const_iterator pit = preamble_snippets_.begin(); FeaturesList::const_iterator pit = preamble_snippets_.begin();
FeaturesList::const_iterator pend = preamble_snippets_.end(); FeaturesList::const_iterator pend = preamble_snippets_.end();
for (; pit != pend; ++pit) { for (; pit != pend; ++pit)
macros << *pit << '\n'; macros << *pit << '\n';
}
if (mustProvide("LyX")) if (mustProvide("LyX"))
macros << lyx_def << '\n'; macros << lyx_def << '\n';
@ -681,17 +680,17 @@ string const LaTeXFeatures::getMacros() const
getFloatDefinitions(macros); getFloatDefinitions(macros);
// change tracking // change tracking
if (mustProvide("ct-dvipost")) { if (mustProvide("ct-dvipost"))
macros << changetracking_dvipost_def; macros << changetracking_dvipost_def;
}
if (mustProvide("ct-xcolor-soul")) { if (mustProvide("ct-xcolor-soul")) {
int const prec = macros.precision(2); int const prec = macros.precision(2);
RGBColor cadd = RGBColor(lcolor.getX11Name(Color_addedtext)); RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
macros << "\\providecolor{lyxadded}{rgb}{" macros << "\\providecolor{lyxadded}{rgb}{"
<< cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n"; << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
RGBColor cdel = RGBColor(lcolor.getX11Name(Color_deletedtext)); RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext));
macros << "\\providecolor{lyxdeleted}{rgb}{" macros << "\\providecolor{lyxdeleted}{rgb}{"
<< cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n"; << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
@ -700,9 +699,9 @@ string const LaTeXFeatures::getMacros() const
macros << "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n" macros << "\\newcommand{\\lyxadded}[3]{{\\color{lyxadded}#3}}\n"
<< "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\st{#3}}}\n"; << "\\newcommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\st{#3}}}\n";
} }
if (mustProvide("ct-none")) {
if (mustProvide("ct-none"))
macros << changetracking_none_def; macros << changetracking_none_def;
}
return macros.str(); return macros.str();
} }

View File

@ -29,6 +29,7 @@
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "CmdDef.h" #include "CmdDef.h"
#include "Color.h"
#include "Converter.h" #include "Converter.h"
#include "Cursor.h" #include "Cursor.h"
#include "CutAndPaste.h" #include "CutAndPaste.h"

View File

@ -196,10 +196,6 @@ liblyxcore_la_SOURCES = \
LyX.h \ LyX.h \
LyXRC.cpp \ LyXRC.cpp \
LyXRC.h \ LyXRC.h \
Server.cpp \
Server.h \
ServerSocket.cpp \
ServerSocket.h \
LyXVC.cpp \ LyXVC.cpp \
LyXVC.h \ LyXVC.h \
MenuBackend.cpp \ MenuBackend.cpp \
@ -240,6 +236,10 @@ liblyxcore_la_SOURCES = \
Row.h \ Row.h \
rowpainter.cpp \ rowpainter.cpp \
rowpainter.h \ rowpainter.h \
Server.cpp \
Server.h \
ServerSocket.cpp \
ServerSocket.h \
Session.cpp \ Session.cpp \
Session.h \ Session.h \
sgml.cpp \ sgml.cpp \

View File

@ -30,7 +30,6 @@
#include "BufferList.h" #include "BufferList.h"
#include "BufferView.h" #include "BufferView.h"
#include "Color.h"
#include "debug.h" #include "debug.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "gettext.h" #include "gettext.h"

View File

@ -18,6 +18,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
#include "Color.h"
#include "EmbeddedFiles.h" #include "EmbeddedFiles.h"
#include "Encoding.h" #include "Encoding.h"
#include "FloatPlacement.h" #include "FloatPlacement.h"

View File

@ -15,6 +15,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BranchList.h" #include "BranchList.h"
#include "Color.h"
#include "Counters.h" #include "Counters.h"
#include "Cursor.h" #include "Cursor.h"
#include "DispatchResult.h" #include "DispatchResult.h"

View File

@ -113,7 +113,7 @@ int InsetHyperlink::latex(Buffer const &, odocstream & os,
// replace the tilde by the \sim character as suggested in the LaTeX FAQ // replace the tilde by the \sim character as suggested in the LaTeX FAQ
// for URLs // for URLs
docstring const sim = from_ascii("$\\sim$"); docstring const sim = from_ascii("$\\sim$");
for (int i = 0, pos; for (size_t i = 0, pos;
(pos = name.find('~', i)) != string::npos; (pos = name.find('~', i)) != string::npos;
i = pos + 1) i = pos + 1)
name.replace(pos, 1, sim); name.replace(pos, 1, sim);