From 09df753df4c24470617c64d25eae6df2db85dfed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 2 Nov 2007 23:42:27 +0000 Subject: [PATCH] pimpl not needed here git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21395 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BranchList.cpp | 7 +- src/BranchList.h | 2 +- src/BufferParams.cpp | 1 + src/Color.cpp | 168 ++++++++++----------------- src/Color.h | 85 ++++++-------- src/ColorCode.h | 21 ++++ src/FontInfo.cpp | 2 +- src/LaTeXFeatures.cpp | 17 ++- src/LyXFunc.cpp | 1 + src/Makefile.am | 8 +- src/frontends/qt4/GuiApplication.cpp | 1 - src/frontends/qt4/GuiDocument.cpp | 1 + src/insets/InsetBranch.cpp | 1 + src/insets/InsetHyperlink.cpp | 4 +- 14 files changed, 141 insertions(+), 178 deletions(-) diff --git a/src/BranchList.cpp b/src/BranchList.cpp index 89884e60a2..b846641e15 100644 --- a/src/BranchList.cpp +++ b/src/BranchList.cpp @@ -11,6 +11,7 @@ #include #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_); diff --git a/src/BranchList.h b/src/BranchList.h index 44f10213eb..68cc46cebc 100644 --- a/src/BranchList.h +++ b/src/BranchList.h @@ -30,7 +30,7 @@ #ifndef BRANCHES_H #define BRANCHES_H -#include "Color.h" +#include "ColorCode.h" #include "support/docstring.h" diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index b2dd1da257..66d94567d0 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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" diff --git a/src/Color.cpp b/src/Color.cpp index c56ecc42fb..93f142399c 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -16,12 +16,15 @@ #include -#include "debug.h" -#include "gettext.h" #include "Color.h" +#include "debug.h" +#include "gettext.h" + #include "support/lstrings.h" +#include + #include #include #include @@ -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 InfoTab; - /// the table of color information - InfoTab infotab; - - typedef std::map 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(pimpl_->infotab.size()), lcname); + addColor(static_cast(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 diff --git a/src/Color.h b/src/Color.h index d632bbce2f..0f0a0934a3 100644 --- a/src/Color.h +++ b/src/Color.h @@ -23,19 +23,13 @@ #include "support/strfwd.h" -#include - +#include +#include 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_; + typedef std::map InfoTab; + /// the table of color Information + InfoTab infotab; + + typedef std::map 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 diff --git a/src/ColorCode.h b/src/ColorCode.h index 3feb992559..c3cbcfd34b 100644 --- a/src/ColorCode.h +++ b/src/ColorCode.h @@ -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 diff --git a/src/FontInfo.cpp b/src/FontInfo.cpp index 7e58b16e3b..e0e0354b0b 100644 --- a/src/FontInfo.cpp +++ b/src/FontInfo.cpp @@ -294,4 +294,4 @@ ColorCode FontInfo::realColor() const return color_; } -} // namespace lyx \ No newline at end of file +} // namespace lyx diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 245267c9b2..1e1b4b22a5 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -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(); } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 8ace0fb13a..7d369bfd70 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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" diff --git a/src/Makefile.am b/src/Makefile.am index 15ec60fd34..0ec29dfbc9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index c604af671b..cc67ead081 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -30,7 +30,6 @@ #include "BufferList.h" #include "BufferView.h" -#include "Color.h" #include "debug.h" #include "FuncRequest.h" #include "gettext.h" diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index b4972b541a..fb30aba07e 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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" diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index a09f130a26..9af5c9e8b7 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -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" diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index d38509b60e..509fedfe7e 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -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);