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 "BranchList.h"
#include "Color.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] == '#')
color_ = RGBColor(c);
if (str.size() == 7 && str[0] == '#')
color_ = rgbFromHexName(str);
else
// no color set or invalid color - use normal background
theApp()->getRgbColor(Color_background, color_);

View File

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

View File

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

View File

@ -16,12 +16,15 @@
#include <config.h>
#include "debug.h"
#include "gettext.h"
#include "Color.h"
#include "debug.h"
#include "gettext.h"
#include "support/lstrings.h"
#include <boost/assert.hpp>
#include <map>
#include <cmath>
#include <sstream>
@ -46,9 +49,7 @@ namespace lyx {
using support::compare_ascii_no_case;
using support::ascii_lowercase;
namespace {
struct ColorEntry {
struct ColorSet::ColorEntry {
ColorCode lcolor;
char const * guiname;
char const * latexname;
@ -56,9 +57,8 @@ struct ColorEntry {
char const * lyxname;
};
int const nohue = -1;
int hexstrToInt(string const & str)
static int hexstrToInt(string const & str)
{
int val = 0;
istringstream is(str);
@ -66,8 +66,6 @@ int hexstrToInt(string const & str)
return val;
}
} // namespace anon
/////////////////////////////////////////////////////////////////////
//
@ -89,66 +87,18 @@ string const X11hexname(RGBColor const & col)
}
RGBColor::RGBColor(string const & x11hexname)
: r(0), g(0), b(0)
RGBColor rgbFromHexName(string const & x11hexname)
{
RGBColor c;
BOOST_ASSERT(x11hexname.size() == 7 && x11hexname[0] == '#');
r = hexstrToInt(x11hexname.substr(1,2));
g = hexstrToInt(x11hexname.substr(3,2));
b = hexstrToInt(x11hexname.substr(5,2));
c.r = hexstrToInt(x11hexname.substr(1,2));
c.g = hexstrToInt(x11hexname.substr(3,2));
c.b = hexstrToInt(x11hexname.substr(5,2));
return c;
}
/////////////////////////////////////////////////////////////////////
//
// 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)
ColorSet::ColorSet()
{
// ColorCode, gui, latex, x11, lyx
static ColorEntry const items[] = {
@ -219,39 +169,37 @@ Color::Color()
};
for (int i = 0; items[i].guiname; ++i)
pimpl_->fill(items[i]);
fill(items[i]);
}
Color::Color(Color const & c)
: pimpl_(new Pimpl(*c.pimpl_))
{}
Color::~Color()
{}
Color & Color::operator=(Color tmp)
/// initialise a color entry
void ColorSet::fill(ColorEntry const & entry)
{
boost::swap(pimpl_, tmp.pimpl_);
return *this;
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;
}
docstring const Color::getGUIName(ColorCode c) const
docstring const ColorSet::getGUIName(ColorCode c) const
{
Pimpl::InfoTab::const_iterator it = pimpl_->infotab.find(c);
if (it != pimpl_->infotab.end())
InfoTab::const_iterator it = infotab.find(c);
if (it != infotab.end())
return _(it->second.guiname);
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);
if (it != pimpl_->infotab.end())
InfoTab::const_iterator it = infotab.find(c);
if (it != infotab.end())
return it->second.x11name;
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);
if (it != pimpl_->infotab.end())
InfoTab::const_iterator it = infotab.find(c);
if (it != infotab.end())
return it->second.latexname;
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);
if (it != pimpl_->infotab.end())
InfoTab::const_iterator it = infotab.find(c);
if (it != infotab.end())
return it->second.lyxname;
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);
if (it == pimpl_->infotab.end()) {
InfoTab::iterator it = infotab.find(col);
if (it == infotab.end()) {
lyxerr << "Color " << col << " not found in database."
<< std::endl;
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);
if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
if (lyxcolors.find(lcname) == lyxcolors.end()) {
LYXERR(Debug::GUI)
<< "Color::setColor: Unknown color \""
<< "ColorSet::setColor: Unknown color \""
<< 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() };
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);
if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) {
lyxerr << "Color::getFromLyXName: Unknown color \""
Transform::const_iterator it = lyxcolors.find(lcname);
if (it == lyxcolors.end()) {
lyxerr << "ColorSet::getFromLyXName: Unknown color \""
<< lyxname << '"' << endl;
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()) {
lyxerr << "Color::getFromLaTeXName: Unknown color \""
Transform::const_iterator it = latexcolors.find(latexname);
if (it == latexcolors.end()) {
lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
<< latexname << '"' << endl;
return Color_none;
}
return pimpl_->latexcolors[latexname];
return it->second;
}
// The evil global Color instance
Color lcolor;
ColorSet lcolor;
// An equally evil global system Color instance
Color system_lcolor;
ColorSet system_lcolor;
} // namespace lyx

View File

@ -23,19 +23,13 @@
#include "support/strfwd.h"
#include <boost/scoped_ptr.hpp>
#include <map>
#include <string>
namespace lyx {
/**
* This is a stateless class.
*
* It has one basic purposes:
* To serve as a color-namespace container (the Color enum).
*/
/**
* \class Color
* \class ColorSet
*
* A class holding color definitions and associated names for
* LaTeX, X11, the GUI, and LyX internally.
@ -46,19 +40,15 @@ namespace lyx {
* - A logical color, such as no color, inherit, math
*/
class Color
// made copyable for same reasons as LyXRC was made copyable. See there for
// explanation.
class ColorSet
{
public:
///
Color();
///
Color(Color const &);
///
~Color();
///
Color & operator=(Color);
ColorSet();
/** set the given LyX color to the color defined by the X11 name given
* \returns true if successful.
@ -87,48 +77,47 @@ public:
ColorCode getFromLyXName(std::string const & lyxname) const;
/// \returns the ColorCode associated with the LaTeX name.
ColorCode getFromLaTeXName(std::string const & latexname) const;
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
extern Color lcolor;
extern ColorSet lcolor;
/// 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);
RGBColor rgbFromHexName(std::string const & x11hexname);
} // namespace lyx

View File

@ -156,6 +156,27 @@ enum ColorCode
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
#endif

View File

@ -294,4 +294,4 @@ ColorCode FontInfo::realColor() const
return color_;
}
} // namespace lyx
} // namespace lyx

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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