On Sun, Feb 08, 2009 at 03:49:49AM +0100, Vincent van Ravesteijn wrote: > OK ?
I am a bit concerned about the includes, but I think that can be handled later by something like the attached patch (untested). Andre'
Index: Color.h =================================================================== --- Color.h (revision 28390) +++ Color.h (working copy) @@ -23,9 +23,6 @@ #include "support/strfwd.h" -#include <map> -#include <string> - namespace lyx { /** @@ -49,6 +46,8 @@ public: /// ColorSet(); + /// + ~ColorSet(); /** set the given LyX color to the color defined by the X11 name given * \returns true if successful. @@ -79,35 +78,13 @@ ColorCode getFromLaTeXName(std::string const & latexname) const; private: - /// - void addColor(ColorCode c, std::string const & lyxname); - /// - 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; - }; + /// non-copiable + ColorSet(ColorSet const &); + void operator=(ColorSet const &); - /// initialise a color entry - struct ColorEntry; - void fill(ColorEntry const & entry); - - /// - 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; + /// Hide details + class Private; + Private * d; }; Index: insets/Inset.cpp =================================================================== --- insets/Inset.cpp (revision 28390) +++ insets/Inset.cpp (working copy) @@ -123,6 +123,16 @@ } +Inset::Inset() + : buffer_(0), parent_(0) +{} + + +Inset::Inset(Inset const &) + : buffer_(0), parent_(0) +{} + + void Inset::setBuffer(Buffer & buffer) { buffer_ = &buffer; Index: insets/Inset.h =================================================================== --- insets/Inset.h (revision 28390) +++ insets/Inset.h (working copy) @@ -96,6 +96,10 @@ /// virtual base class destructor virtual ~Inset() {} + /// change parent inset + void setParent(Inset * parent) { parent_ = parent; } + Inset *parent() const { return parent_; } + /// change associated Buffer /// FIXME this should go. virtual void setBuffer(Buffer & buffer); @@ -514,8 +518,8 @@ protected: /// Constructors - Inset() : buffer_(0) {} - Inset(Inset const &) : buffer_(0) {} + Inset(); + Inset(Inset const &); /// replicate ourselves friend class InsetList; @@ -536,6 +540,8 @@ virtual void doDispatch(Cursor & cur, FuncRequest & cmd); Buffer * buffer_; + + Inset * parent_; }; } // namespace lyx Index: LyX.cpp =================================================================== --- LyX.cpp (revision 28390) +++ LyX.cpp (working copy) @@ -21,7 +21,6 @@ #include "Buffer.h" #include "BufferList.h" #include "CmdDef.h" -#include "Color.h" #include "ConverterCache.h" #include "Converter.h" #include "CutAndPaste.h" @@ -713,7 +712,6 @@ system_formats = formats; pimpl_->system_converters_ = pimpl_->converters_; pimpl_->system_movers_ = pimpl_->movers_; - system_lcolor = lcolor; // This one is edited through the preferences dialog. if (!readRcFile("preferences")) Index: Color.cpp =================================================================== --- Color.cpp (revision 28390) +++ Color.cpp (working copy) @@ -32,18 +32,100 @@ using namespace std; using namespace lyx::support; -namespace lyx { +///////////////////////////////////////////////////////////////////////// +// +// ColorEntry +// +/////////////////////////////////////////////////////////////////////////// +namespace { -struct ColorSet::ColorEntry { - ColorCode lcolor; +struct ColorEntry +{ + lyx::ColorCode lcolor; char const * guiname; char const * latexname; char const * x11name; char const * lyxname; }; +} // namespace anon + +///////////////////////////////////////////////////////////////////////// +// +// ColorInformation +// +/////////////////////////////////////////////////////////////////////////// + +namespace { + +struct ColorInformation +{ + /// 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; +}; + +/// +typedef std::map<lyx::ColorCode, ColorInformation> InfoTab; +/// +typedef std::map<std::string, lyx::ColorCode> Transform; + +} // namespace anon + + +///////////////////////////////////////////////////////////////////////// +// +// ColorSet::Private +// +/////////////////////////////////////////////////////////////////////////// + +namespace lyx { + +class ColorSet::Private +{ +public: + void addColor(ColorCode c, std::string const & lyxname); + /// + /// initialise a color entry + void fill(ColorEntry const & entry); + + /// the table of color Information + InfoTab infotab; + + /// the transform between LyX color name string and integer code. + Transform lyxcolors; + /// the transform between LaTeX color name string and integer code. + Transform latexcolors; +}; + + +/// initialise a color entry +void ColorSet::Private::fill(ColorEntry const & entry) +{ + ColorInformation 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; +} + +void ColorSet::Private::addColor(ColorCode c, string const & lyxname) +{ + ColorEntry ce = { c, "", "", "", lyxname.c_str() }; + fill(ce); +} + + static int hexstrToInt(string const & str) { int val = 0; @@ -84,8 +166,15 @@ } +///////////////////////////////////////////////////////////////////////// +// +// ColorSet +// +/////////////////////////////////////////////////////////////////////////// + ColorSet::ColorSet() { + d = new Private; char const * grey40 = "#666666"; char const * grey60 = "#999999"; char const * grey80 = "#cccccc"; @@ -181,28 +270,20 @@ }; for (int i = 0; items[i].guiname; ++i) - fill(items[i]); + d->fill(items[i]); } -/// initialise a color entry -void ColorSet::fill(ColorEntry const & entry) +ColorSet::~ColorSet() { - 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; + delete d; } docstring const ColorSet::getGUIName(ColorCode c) const { - InfoTab::const_iterator it = infotab.find(c); - if (it != infotab.end()) + InfoTab::const_iterator it = d->infotab.find(c); + if (it != d->infotab.end()) return _(it->second.guiname); return from_ascii("none"); } @@ -210,8 +291,8 @@ string const ColorSet::getX11Name(ColorCode c) const { - InfoTab::const_iterator it = infotab.find(c); - if (it != infotab.end()) + InfoTab::const_iterator it = d->infotab.find(c); + if (it != d->infotab.end()) return it->second.x11name; lyxerr << "LyX internal error: Missing color" @@ -223,8 +304,8 @@ string const ColorSet::getLaTeXName(ColorCode c) const { - InfoTab::const_iterator it = infotab.find(c); - if (it != infotab.end()) + InfoTab::const_iterator it = d->infotab.find(c); + if (it != d->infotab.end()) return it->second.latexname; return "black"; } @@ -232,8 +313,8 @@ string const ColorSet::getLyXName(ColorCode c) const { - InfoTab::const_iterator it = infotab.find(c); - if (it != infotab.end()) + InfoTab::const_iterator it = d->infotab.find(c); + if (it != d->infotab.end()) return it->second.lyxname; return "black"; } @@ -241,8 +322,8 @@ bool ColorSet::setColor(ColorCode col, string const & x11name) { - InfoTab::iterator it = infotab.find(col); - if (it == infotab.end()) { + InfoTab::iterator it = d->infotab.find(col); + if (it == d->infotab.end()) { LYXERR0("Color " << col << " not found in database."); return false; } @@ -262,28 +343,21 @@ bool ColorSet::setColor(string const & lyxname, string const &x11name) { string const lcname = ascii_lowercase(lyxname); - if (lyxcolors.find(lcname) == lyxcolors.end()) { + if (d->lyxcolors.find(lcname) == d->lyxcolors.end()) { LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \"" << lyxname << '"'); - addColor(static_cast<ColorCode>(infotab.size()), lcname); + d->addColor(static_cast<ColorCode>(d->infotab.size()), lcname); } - return setColor(lyxcolors[lcname], x11name); + return setColor(d->lyxcolors[lcname], x11name); } -void ColorSet::addColor(ColorCode c, string const & lyxname) -{ - ColorEntry ce = { c, "", "", "", lyxname.c_str() }; - fill(ce); -} - - ColorCode ColorSet::getFromLyXName(string const & lyxname) const { string const lcname = ascii_lowercase(lyxname); - Transform::const_iterator it = lyxcolors.find(lcname); - if (it == lyxcolors.end()) { + Transform::const_iterator it = d->lyxcolors.find(lcname); + if (it == d->lyxcolors.end()) { LYXERR0("ColorSet::getFromLyXName: Unknown color \"" << lyxname << '"'); return Color_none; @@ -295,8 +369,8 @@ ColorCode ColorSet::getFromLaTeXName(string const & latexname) const { - Transform::const_iterator it = latexcolors.find(latexname); - if (it == latexcolors.end()) { + Transform::const_iterator it = d->latexcolors.find(latexname); + if (it == d->latexcolors.end()) { lyxerr << "ColorSet::getFromLaTeXName: Unknown color \"" << latexname << '"' << endl; return Color_none;