mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Store colors as rgb values in branches.
* src/frontends/xforms/Color.[Ch]: move to src * src/Color.[Ch] (getRGBColor): move to src/frontends/*/lyx_gui.C * src/BranchList.h (Branch::color_): change type to lyx::RGBColor * src/BranchList.[Ch] (Branch): new constrcutor, set color_ to LColor::background (getColor, setColor): adapt to type change of color_ * src/bufferparams.C (BufferParams::writeFile): adapt to type change of branch color * src/frontends/lyx_gui.h * src/frontends/gtk/lyx_gui.C * src/frontends/qt2/lyx_gui.C * src/frontends/qt4/lyx_gui.C * src/frontends/xforms/lyx_gui.C (getRGBColor): move from src/Color.[Ch] here * src/frontends/gtk/lyx_gui.C * src/frontends/xforms/lyx_gui.C (hexname): use getRGBColor * src/frontends/gtk/GDocument.C (update): adapt to type change of branch color (apply): add comment about color chooser * src/frontends/qt2/QDocumentDialog.C (updateBranchView): adapt to type change of branch color (toggleBranchColor): ditto * src/frontends/qt2/lcolorcache.[Ch] * src/frontends/qt4/lcolorcache.[Ch] (rgb2qcolor): new utility function * src/frontends/qt4/QBranches.C (QBranches::update): adapt to type change of branch color (QBranches::on_colorPB_clicked): ditto * src/frontends/xforms/FormDocument.C (get_current_color): adapt to type change of branch color (FormDocument::branch_update): * src/frontends/xforms/FormPreferences.C (FormPreferences::Colors::LoadBrowse): adapt to RGBColor changes * src/frontends/xforms/FormPreferences.h: remove unneeded RGBColor forward declaration * src/frontends/xforms/XWorkArea.C (XWorkArea::XWorkArea): adapt to RGBColor changes * src/frontends/xforms/Makefile.am: remove Color.[Ch] * src/frontends/xforms/FormColorpicker.[Ch]: adapt to RGBColor changes * src/frontends/xforms/xformsImage.C: adapt to RGBColor changes * src/frontends/controllers/ControlDocument.C (ControlDocument::dispatchParams): adapt to type change of branch color * src/Makefile.am: add Color.[Ch] git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13466 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f44bd092bc
commit
399e6e788c
@ -11,11 +11,19 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "BranchList.h"
|
||||
#include "LColor.h"
|
||||
#include "frontends/lyx_gui.h"
|
||||
#include <algorithm>
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
Branch::Branch()
|
||||
{
|
||||
lyx_gui::getRGBColor(LColor::background, color_);
|
||||
}
|
||||
|
||||
|
||||
string const & Branch::getBranch() const
|
||||
{
|
||||
return branch_;
|
||||
@ -43,18 +51,28 @@ bool Branch::setSelected(bool b)
|
||||
}
|
||||
|
||||
|
||||
string const & Branch::getColor() const
|
||||
lyx::RGBColor const & Branch::getColor() const
|
||||
{
|
||||
return color_;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(string const & c)
|
||||
void Branch::setColor(lyx::RGBColor const & c)
|
||||
{
|
||||
color_ = c;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(string const & c)
|
||||
{
|
||||
if (c.size() == 7 && c[0] == '#')
|
||||
color_ = lyx::RGBColor(c);
|
||||
else
|
||||
// no color set or invalid color - use normal background
|
||||
lyx_gui::getRGBColor(LColor::background, color_);
|
||||
}
|
||||
|
||||
|
||||
Branch * BranchList::find(std::string const & name)
|
||||
{
|
||||
List::iterator it =
|
||||
@ -91,7 +109,6 @@ bool BranchList::add(string const & s)
|
||||
Branch br;
|
||||
br.setBranch(name);
|
||||
br.setSelected(false);
|
||||
br.setColor("none");
|
||||
list.push_back(br);
|
||||
}
|
||||
if (j == string::npos)
|
||||
|
@ -30,12 +30,16 @@
|
||||
#ifndef BRANCHES_H
|
||||
#define BRANCHES_H
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
|
||||
class Branch {
|
||||
public:
|
||||
///
|
||||
Branch();
|
||||
///
|
||||
std::string const & getBranch() const;
|
||||
///
|
||||
@ -47,8 +51,15 @@ public:
|
||||
*/
|
||||
bool setSelected(bool);
|
||||
///
|
||||
std::string const & getColor() const;
|
||||
lyx::RGBColor const & getColor() const;
|
||||
///
|
||||
void setColor(lyx::RGBColor const &);
|
||||
/**
|
||||
* Set color from a string "#rrggbb".
|
||||
* Use LColor:background if the string is no valid color.
|
||||
* This ensures compatibility with LyX 1.4.0 that had the symbolic
|
||||
* color "none" that was displayed as LColor:background.
|
||||
*/
|
||||
void setColor(std::string const &);
|
||||
|
||||
|
||||
@ -58,7 +69,7 @@ private:
|
||||
///
|
||||
bool selected_;
|
||||
///
|
||||
std::string color_;
|
||||
lyx::RGBColor color_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include "lyx_forms.h"
|
||||
|
||||
#include "LColor.h"
|
||||
|
||||
#include <cmath>
|
||||
@ -33,7 +31,6 @@ using std::ostringstream;
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -51,28 +48,6 @@ int hexstrToInt(string const & str)
|
||||
|
||||
|
||||
|
||||
bool getRGBColor(LColor_color col,
|
||||
unsigned int & r, unsigned int & g, unsigned int & b)
|
||||
{
|
||||
string const name = lcolor.getX11Name(col);
|
||||
Display * const display = fl_get_display();
|
||||
Colormap const cmap = fl_state[fl_get_vclass()].colormap;
|
||||
XColor xcol, ccol;
|
||||
|
||||
if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
r = xcol.red / 256;
|
||||
g = xcol.green / 256;
|
||||
b = xcol.blue / 256;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const X11hexname(RGBColor const & col)
|
||||
{
|
||||
ostringstream ostr;
|
||||
@ -199,5 +174,4 @@ HSVColor::HSVColor(RGBColor const & rgb)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
@ -18,16 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class LColor_color;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/** Given col, fills r, g, b in the range 0-255.
|
||||
The function returns true if successful.
|
||||
It returns false on failure and sets r, g, b to 0. */
|
||||
bool getRGBColor(LColor_color col,
|
||||
unsigned int & r, unsigned int & g, unsigned int & b);
|
||||
|
||||
struct RGBColor;
|
||||
/// returns a string of form #rrggbb, given an RGBColor struct
|
||||
@ -78,7 +69,6 @@ bool operator!=(RGBColor const & c1, RGBColor const & c2)
|
||||
return !(c1 == c2);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -85,6 +85,8 @@ lyx_SOURCES = \
|
||||
BranchList.h \
|
||||
Chktex.C \
|
||||
Chktex.h \
|
||||
Color.C \
|
||||
Color.h \
|
||||
CutAndPaste.C \
|
||||
CutAndPaste.h \
|
||||
DepTable.C \
|
||||
|
@ -601,7 +601,7 @@ void BufferParams::writeFile(ostream & os) const
|
||||
for (; it != end; ++it) {
|
||||
os << "\\branch " << it->getBranch()
|
||||
<< "\n\\selected " << it->getSelected()
|
||||
<< "\n\\color " << it->getColor()
|
||||
<< "\n\\color " << lyx::X11hexname(it->getColor())
|
||||
<< "\n\\end_branch"
|
||||
<< "\n";
|
||||
}
|
||||
|
@ -114,11 +114,8 @@ void ControlDocument::dispatchParams()
|
||||
for (; it != end; ++it) {
|
||||
string const & current_branch = it->getBranch();
|
||||
Branch const * branch = branchlist.find(current_branch);
|
||||
string x11hexname = branch->getColor();
|
||||
// check that we have a valid color!
|
||||
if (x11hexname.empty() || x11hexname[0] != '#')
|
||||
x11hexname =
|
||||
lcolor.getX11Name(LColor::background);
|
||||
string const x11hexname =
|
||||
lyx::X11hexname(branch->getColor());
|
||||
// display the new color
|
||||
string const str = current_branch + ' ' + x11hexname;
|
||||
kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
|
||||
|
@ -529,7 +529,7 @@ void GDocument::update()
|
||||
(*row)[branchColName_] = (*it).getBranch();
|
||||
std::cerr << "update: loading '" << (*it).getBranch() << "'\n";
|
||||
(*row)[branchColActivated_] = (*it).getSelected();
|
||||
(*row)[branchColColor_] = (*it).getColor();
|
||||
(*row)[branchColColor_] = X11hexname((*it).getColor());
|
||||
}
|
||||
// *** End "Branches" Page ***
|
||||
|
||||
@ -720,6 +720,10 @@ void GDocument::apply()
|
||||
Branch * newbranch = branchlist.find(name);
|
||||
newbranch->setSelected((*row)[branchColActivated_]);
|
||||
Glib::ustring const color = (*row)[branchColColor_];
|
||||
// FIXME: The color should be editable via a color
|
||||
// chooser, not a text field (see qt/xforms frontends)
|
||||
// setColor will silently ignore an invalid color and
|
||||
// use the normal background color for now.
|
||||
newbranch->setColor(color);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "Color.h"
|
||||
#include "LColor.h"
|
||||
#include "LyXAction.h"
|
||||
#include "lyx_main.h"
|
||||
@ -175,23 +176,44 @@ FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
|
||||
}
|
||||
|
||||
|
||||
string const lyx_gui::hexname(LColor_color col)
|
||||
bool lyx_gui::getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
|
||||
{
|
||||
Gdk::Color gdkColor;
|
||||
Gdk::Color * gclr = colorCache.getColor(col);
|
||||
if (!gclr) {
|
||||
gclr = &gdkColor;
|
||||
gclr->parse(lcolor.getX11Name(col));
|
||||
if(!gclr->parse(lcolor.getX11Name(col))) {
|
||||
rgbcol.r = 0;
|
||||
rgbcol.g = 0;
|
||||
rgbcol.b = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Note that X stores the RGB values in the range 0 - 65535
|
||||
// whilst we require them in the range 0 - 255.
|
||||
rgbcol.r = gclr->get_red() / 256;
|
||||
rgbcol.g = gclr->get_green() / 256;
|
||||
rgbcol.b = gclr->get_blue() / 256;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const lyx_gui::hexname(LColor_color col)
|
||||
{
|
||||
lyx::RGBColor rgbcol;
|
||||
if (!getRGBColor(col, rgbcol)) {
|
||||
lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
|
||||
<< '"' << std::endl;
|
||||
return string();
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
// Note that X stores the RGB values in the range 0 - 65535
|
||||
// whilst we require them in the range 0 - 255.
|
||||
os << std::setbase(16) << std::setfill('0')
|
||||
<< std::setw(2) << (gclr->get_red() / 256)
|
||||
<< std::setw(2) << (gclr->get_green() / 256)
|
||||
<< std::setw(2) << (gclr->get_blue() / 256);
|
||||
<< std::setw(2) << rgbcol.r
|
||||
<< std::setw(2) << rgbcol.g
|
||||
<< std::setw(2) << rgbcol.b;
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ class LyXComm;
|
||||
class LyXDataSocket;
|
||||
class LyXServerSocket;
|
||||
class FuncRequest;
|
||||
namespace lyx {
|
||||
struct RGBColor;
|
||||
}
|
||||
|
||||
/// GUI interaction
|
||||
namespace lyx_gui {
|
||||
@ -74,6 +77,13 @@ void exit();
|
||||
*/
|
||||
FuncStatus getStatus(FuncRequest const & ev);
|
||||
|
||||
/**
|
||||
* Given col, fills r, g, b in the range 0-255.
|
||||
* The function returns true if successful.
|
||||
* It returns false on failure and sets r, g, b to 0.
|
||||
*/
|
||||
bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol);
|
||||
|
||||
/** Eg, passing LColor::black returns "000000",
|
||||
* passing LColor::white returns "ffffff".
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "QDocumentDialog.h"
|
||||
|
||||
#include "floatplacement.h"
|
||||
#include "lcolorcache.h"
|
||||
#include "lengthcombo.h"
|
||||
#include "validators.h"
|
||||
#include "panelstack.h"
|
||||
@ -421,10 +422,7 @@ void QDocumentDialog::updateBranchView()
|
||||
QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
|
||||
QListViewItem * newItem =
|
||||
new QListViewItem(branchesModule->branchesLV, bname, sel);
|
||||
string const x11hexname = it->getColor();
|
||||
QColor itemcolor;
|
||||
if (x11hexname[0] == '#')
|
||||
itemcolor.setNamedColor(toqstr(x11hexname));
|
||||
QColor const itemcolor = rgb2qcolor(it->getColor());
|
||||
if (itemcolor.isValid()) {
|
||||
QPixmap coloritem(30, 10);
|
||||
coloritem.fill(itemcolor);
|
||||
@ -503,16 +501,13 @@ void QDocumentDialog::toggleBranchColor()
|
||||
if (selItem != 0)
|
||||
sel_branch = selItem->text(0);
|
||||
if (sel_branch) {
|
||||
QColor initial;
|
||||
string current_branch = fromqstr(sel_branch);
|
||||
Branch * branch =
|
||||
form_->branchlist_.find(current_branch);
|
||||
if (!branch)
|
||||
return;
|
||||
|
||||
string x11hexname = branch->getColor();
|
||||
if (x11hexname[0] == '#')
|
||||
initial.setNamedColor(toqstr(x11hexname));
|
||||
QColor const initial = rgb2qcolor(branch->getColor());
|
||||
QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
|
||||
if (ncol.isValid()){
|
||||
// add the color to the branchlist
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "lcolorcache.h"
|
||||
|
||||
#include "Color.h"
|
||||
#include "LColor.h"
|
||||
|
||||
LColorCache lcolorcache;
|
||||
@ -38,3 +39,9 @@ void LColorCache::clear()
|
||||
{
|
||||
colormap.clear();
|
||||
}
|
||||
|
||||
|
||||
QColor const rgb2qcolor(lyx::RGBColor const & rgb)
|
||||
{
|
||||
return QColor(rgb.r, rgb.g, rgb.b);
|
||||
}
|
||||
|
@ -19,6 +19,11 @@
|
||||
#include <qcolor.h>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
struct RGBColor;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: use a fixed-size array not a map ?
|
||||
|
||||
/**
|
||||
@ -43,4 +48,6 @@ private:
|
||||
/// singleton instance
|
||||
extern LColorCache lcolorcache;
|
||||
|
||||
///
|
||||
QColor const rgb2qcolor(lyx::RGBColor const &);
|
||||
#endif // LCOLORCACHE_H
|
||||
|
@ -16,6 +16,7 @@
|
||||
// FIXME: move this stuff out again
|
||||
#include "bufferlist.h"
|
||||
#include "BufferView.h"
|
||||
#include "Color.h"
|
||||
#include "funcrequest.h"
|
||||
#include "LColor.h"
|
||||
#include "lyx_main.h"
|
||||
@ -300,6 +301,22 @@ FuncStatus getStatus(FuncRequest const & ev)
|
||||
}
|
||||
|
||||
|
||||
bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
|
||||
{
|
||||
QColor const & qcol = lcolorcache.get(col);
|
||||
if (!qcol.isValid()) {
|
||||
rgbcol.r = 0;
|
||||
rgbcol.g = 0;
|
||||
rgbcol.b = 0;
|
||||
return false;
|
||||
}
|
||||
rgbcol.r = qcol.red();
|
||||
rgbcol.g = qcol.green();
|
||||
rgbcol.b = qcol.blue();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const hexname(LColor_color col)
|
||||
{
|
||||
return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "QBranches.h"
|
||||
|
||||
#include "lcolorcache.h"
|
||||
#include "validators.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
@ -68,10 +69,7 @@ void QBranches::update()
|
||||
QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
|
||||
Q3ListViewItem * newItem =
|
||||
new Q3ListViewItem(branchesLV, bname, sel);
|
||||
string const x11hexname = it->getColor();
|
||||
QColor itemcolor;
|
||||
if (x11hexname[0] == '#')
|
||||
itemcolor.setNamedColor(toqstr(x11hexname));
|
||||
QColor const itemcolor = rgb2qcolor(it->getColor());
|
||||
if (itemcolor.isValid()) {
|
||||
QPixmap coloritem(30, 10);
|
||||
coloritem.fill(itemcolor);
|
||||
@ -154,16 +152,13 @@ void QBranches::on_colorPB_clicked()
|
||||
if (selItem != 0)
|
||||
sel_branch = selItem->text(0);
|
||||
if (!sel_branch.isEmpty()) {
|
||||
QColor initial("lightskyblue");
|
||||
string current_branch = fromqstr(sel_branch);
|
||||
Branch * branch =
|
||||
branchlist_.find(current_branch);
|
||||
if (!branch)
|
||||
return;
|
||||
|
||||
string x11hexname = branch->getColor();
|
||||
if (x11hexname[0] == '#')
|
||||
initial.setNamedColor(toqstr(x11hexname));
|
||||
QColor const initial = rgb2qcolor(branch->getColor());
|
||||
QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget()));
|
||||
if (ncol.isValid()){
|
||||
// add the color to the branchlist
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "Color.h"
|
||||
#include "lcolorcache.h"
|
||||
|
||||
#include "LColor.h"
|
||||
@ -51,3 +52,9 @@ void LColorCache::clear()
|
||||
{
|
||||
colormap.clear();
|
||||
}
|
||||
|
||||
|
||||
QColor const rgb2qcolor(lyx::RGBColor const & rgb)
|
||||
{
|
||||
return QColor(rgb.r, rgb.g, rgb.b);
|
||||
}
|
||||
|
@ -19,6 +19,11 @@
|
||||
#include <QColor>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
struct RGBColor;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: use a fixed-size array not a map ?
|
||||
|
||||
/**
|
||||
@ -43,4 +48,6 @@ private:
|
||||
/// singleton instance
|
||||
extern LColorCache lcolorcache;
|
||||
|
||||
///
|
||||
QColor const rgb2qcolor(lyx::RGBColor const &);
|
||||
#endif // LCOLORCACHE_H
|
||||
|
@ -16,6 +16,7 @@
|
||||
// FIXME: move this stuff out again
|
||||
#include "bufferlist.h"
|
||||
#include "BufferView.h"
|
||||
#include "Color.h"
|
||||
#include "funcrequest.h"
|
||||
#include "LColor.h"
|
||||
#include "lyx_main.h"
|
||||
@ -294,6 +295,22 @@ FuncStatus getStatus(FuncRequest const & ev)
|
||||
}
|
||||
|
||||
|
||||
bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
|
||||
{
|
||||
QColor const & qcol = lcolorcache.get(col);
|
||||
if (!qcol.isValid()) {
|
||||
rgbcol.r = 0;
|
||||
rgbcol.g = 0;
|
||||
rgbcol.b = 0;
|
||||
return false;
|
||||
}
|
||||
rgbcol.r = qcol.red();
|
||||
rgbcol.g = qcol.green();
|
||||
rgbcol.b = qcol.blue();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const hexname(LColor_color col)
|
||||
{
|
||||
return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "lyx_forms.h"
|
||||
|
||||
using lyx::RGBColor;
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
a color is chosen (or the dialog is closed).
|
||||
\param color the color used to initialise the dialog.
|
||||
*/
|
||||
RGBColor const & requestColor(RGBColor const & color);
|
||||
lyx::RGBColor const & requestColor(lyx::RGBColor const & color);
|
||||
|
||||
/** Input callback function.
|
||||
* Invoked only by the xforms callback interface
|
||||
@ -71,8 +71,8 @@ private:
|
||||
/// The title displayed by the Window Manager.
|
||||
std::string title_;
|
||||
|
||||
RGBColor input_color_;
|
||||
RGBColor color_;
|
||||
lyx::RGBColor input_color_;
|
||||
lyx::RGBColor color_;
|
||||
bool finished_;
|
||||
|
||||
/// Passed to the window manager to give a pretty little symbol ;-)
|
||||
|
@ -678,21 +678,13 @@ RGBColor get_current_color(FL_OBJECT * browser, BranchList const & branchlist)
|
||||
{
|
||||
BOOST_ASSERT(browser && browser->objclass == FL_BROWSER);
|
||||
|
||||
RGBColor color;
|
||||
|
||||
int const i = fl_get_browser(browser);
|
||||
string const branch_name = fl_get_browser_line(browser, i);
|
||||
Branch const * branch = branchlist.find(branch_name);
|
||||
if (!branch)
|
||||
return color;
|
||||
return RGBColor();
|
||||
|
||||
string const x11hexname = branch->getColor();
|
||||
if (x11hexname[0] == '#') {
|
||||
color = RGBColor(x11hexname);
|
||||
} else{
|
||||
fl_getmcolor(FL_COL1, &color.r, &color.g, &color.b);
|
||||
}
|
||||
return color;
|
||||
return branch->getColor();
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
@ -1298,20 +1290,16 @@ void FormDocument::branch_update(BufferParams const & params)
|
||||
|
||||
// display proper colour...
|
||||
RGBColor rgb;
|
||||
string x11hexname;
|
||||
if (current_branch == "none")
|
||||
x11hexname = "none";
|
||||
fl_getmcolor(FL_COL1, &rgb.r, &rgb.g, &rgb.b);
|
||||
else {
|
||||
Branch * branch = branchlist_.find(current_branch);
|
||||
if (branch)
|
||||
x11hexname = branch->getColor();
|
||||
}
|
||||
|
||||
if (x11hexname[0] == '#') {
|
||||
rgb = RGBColor(x11hexname);
|
||||
} else {
|
||||
rgb = branch->getColor();
|
||||
else
|
||||
fl_getmcolor(FL_COL1, &rgb.r, &rgb.g, &rgb.b);
|
||||
}
|
||||
|
||||
fl_mapcolor(GUI_COLOR_CHOICE, rgb.r, rgb.g, rgb.b);
|
||||
fl_redraw_object(branch_->button_color);
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "lastfiles.h"
|
||||
#include "LColor.h"
|
||||
#include "lyxfont.h"
|
||||
#include "frontends/lyx_gui.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/lstrings.h"
|
||||
@ -38,6 +39,8 @@
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
using lyx::RGBColor;
|
||||
|
||||
using std::endl;
|
||||
using std::make_pair;
|
||||
using std::max;
|
||||
@ -621,7 +624,7 @@ void FormPreferences::Colors::LoadBrowserLyX()
|
||||
|| lc == LColor::ignore) continue;
|
||||
|
||||
RGBColor col;
|
||||
bool const success = getRGBColor(lc, col.r, col.g, col.b);
|
||||
bool const success = lyx_gui::getRGBColor(lc, col);
|
||||
if (!success) {
|
||||
lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
|
||||
<< "LColor " << lcolor.getLyXName(lc)
|
||||
|
@ -50,7 +50,6 @@ struct FD_preferences_screen_fonts;
|
||||
struct FD_preferences_spelloptions;
|
||||
|
||||
class FormColorpicker;
|
||||
class RGBColor;
|
||||
|
||||
/** This class provides an XForms implementation of the FormPreferences Dialog.
|
||||
* The preferences dialog allows users to set/save their preferences.
|
||||
|
@ -60,8 +60,6 @@ libxforms_la_SOURCES = \
|
||||
xscreen.C \
|
||||
xscreen.h \
|
||||
Alert_pimpl.C \
|
||||
Color.C \
|
||||
Color.h \
|
||||
ColorHandler.C \
|
||||
ColorHandler.h \
|
||||
Dialogs.C \
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Color.h"
|
||||
#include "XFormsView.h"
|
||||
#include "XLyXKeySym.h"
|
||||
#include "lyx_gui.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "funcrequest.h"
|
||||
@ -119,9 +120,9 @@ XWorkArea::XWorkArea(LyXView & owner, int w, int h)
|
||||
fl_set_object_resize(obj, FL_RESIZE_ALL);
|
||||
fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
|
||||
|
||||
unsigned int r, g, b;
|
||||
if (getRGBColor(LColor::background, r, g, b)) {
|
||||
fl_mapcolor(FL_FREE_COL12, r, g, b);
|
||||
RGBColor col;
|
||||
if (lyx_gui::getRGBColor(LColor::background, col)) {
|
||||
fl_mapcolor(FL_FREE_COL12, col.r, col.g, col.b);
|
||||
fl_set_object_color(obj, FL_FREE_COL12, FL_MCOL);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,6 @@ using lyx::support::AddName;
|
||||
using lyx::support::package;
|
||||
|
||||
using lyx::frontend::fontloader;
|
||||
using lyx::frontend::getRGBColor;
|
||||
using lyx::frontend::lyxColorHandler;
|
||||
using lyx::frontend::LyXColorHandler;
|
||||
using lyx::frontend::XformsColor;
|
||||
@ -348,11 +347,34 @@ FuncStatus getStatus(FuncRequest const & /*ev*/)
|
||||
return FuncStatus();
|
||||
}
|
||||
|
||||
|
||||
bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
|
||||
{
|
||||
string const name = lcolor.getX11Name(col);
|
||||
Display * const display = fl_get_display();
|
||||
Colormap const cmap = fl_state[fl_get_vclass()].colormap;
|
||||
XColor xcol, ccol;
|
||||
|
||||
if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
|
||||
rgbcol.r = 0;
|
||||
rgbcol.g = 0;
|
||||
rgbcol.b = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note that X stores the RGB values in the range 0 - 65535
|
||||
// whilst we require them in the range 0 - 255.
|
||||
rgbcol.r = xcol.red / 256;
|
||||
rgbcol.g = xcol.green / 256;
|
||||
rgbcol.b = xcol.blue / 256;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const hexname(LColor_color col)
|
||||
{
|
||||
unsigned int r, g, b;
|
||||
bool const success = getRGBColor(col, r, g, b);
|
||||
if (!success) {
|
||||
lyx::RGBColor rgbcol;
|
||||
if (!getRGBColor(col, rgbcol)) {
|
||||
lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
|
||||
<< '"' << endl;
|
||||
return string();
|
||||
@ -361,9 +383,9 @@ string const hexname(LColor_color col)
|
||||
ostringstream os;
|
||||
|
||||
os << setbase(16) << setfill('0')
|
||||
<< setw(2) << r
|
||||
<< setw(2) << g
|
||||
<< setw(2) << b;
|
||||
<< setw(2) << rgbcol.r
|
||||
<< setw(2) << rgbcol.g
|
||||
<< setw(2) << rgbcol.b;
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "xformsImage.h"
|
||||
#include "Color.h"
|
||||
#include "lyx_gui.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "format.h"
|
||||
@ -33,8 +34,6 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
using lyx::frontend::getRGBColor;
|
||||
|
||||
using lyx::support::float_equal;
|
||||
using lyx::support::prefixIs;
|
||||
using lyx::support::rtrim;
|
||||
@ -470,13 +469,13 @@ void init_graphics()
|
||||
|
||||
unsigned int packedcolor(LColor::color col)
|
||||
{
|
||||
unsigned int r, g, b;
|
||||
bool const success = getRGBColor(col, r, g, b);
|
||||
lyx::RGBColor rgb;
|
||||
bool const success = lyx_gui::getRGBColor(col, rgb);
|
||||
if (!success)
|
||||
// Set to black on failure
|
||||
return FL_PACK(255, 255, 255);
|
||||
|
||||
return FL_PACK(r, g, b);
|
||||
return FL_PACK(rgb.r, rgb.g, rgb.b);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
Loading…
Reference in New Issue
Block a user