+2003-02-11 Angus Leeming <leeming@lyx.org>
+
+ * xforms_helpers.[Ch] (fl_getmcolor): new function; a wrapper for the
+ xforms routine that accepts unsigned ints.
+
+ * Color.[Ch] (getRGBColor): factorise code into one place.
+
+ * FormPreferences.[Ch] (X11hexname: not a class member. Move to
+ namespace anon.
+
+ * FormPreferences.C: use fl_getmcolor and getRGBColor.
+ * lyx_gui.C: use getRGBColor.
+ * xformsImage.C: use getRGBColor.
+
2003-02-11 Angus Leeming <leeming@lyx.org>
* bmtable.c: whitespace and indentation consistent with the other
} // namespace anon
+
+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;
+}
+
+
RGBColor::RGBColor(HSVColor const & hsv)
{
double h = hsv.h;
#endif
#include "LString.h"
+#include "LColor.h"
+
+/** 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;
};
struct RGBColor {
- int r;
- int g;
- int b;
+ unsigned int r;
+ unsigned int g;
+ unsigned int b;
RGBColor() : r(0), g(0), b(0) {}
- RGBColor(int red, int green, int blue)
+ RGBColor(unsigned int red, unsigned int green, unsigned int blue)
: r(red), g(green), b(blue) {}
RGBColor(HSVColor const &);
};
}
+string const X11hexname(RGBColor const & col)
+{
+ ostringstream ostr;
+
+ ostr << '#' << std::setbase(16) << setfill('0')
+ << setw(2) << col.r
+ << setw(2) << col.g
+ << setw(2) << col.b;
+
+ return STRCONV(ostr.str());
+}
+
} // namespace anon
fl_redraw_object(dialog_->button_color);
col = HSVColor(hue, 1.0, 1.0);
- col.r = max(col.r, 0);
+ col.r = max(col.r, 0u);
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
fl_redraw_object(dialog_->dial_hue);
|| lc == LColor::inherit
|| lc == LColor::ignore) continue;
- string const name = lcolor.getX11Name(lc);
- Display * display = fl_get_display();;
- Colormap const colormap = fl_state[fl_get_vclass()].colormap;
- XColor xcol, ccol;
-
- if (XLookupColor(display, colormap, name.c_str(), &xcol, &ccol)
- == 0) {
+ RGBColor col;
+ bool const success = getRGBColor(lc, col.r, col.g, col.b);
+ if (!success) {
lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
<< "LColor " << lcolor.getLyXName(lc)
- << ": X can't find color \"" << name
+ << ": X can't find color \""
+ << lcolor.getX11Name(lc)
<< "\". Set to \"black\"!" << endl;
string const arg = lcolor.getLyXName(lc) + " black";
continue;
}
- // X has found the color. Now find the "appropriate" X11 name
- // for this color.
-
- // Note that X stores the RGB values in the range 0 - 65535
- // whilst we require them in the range 0 - 255.
- RGBColor col;
- col.r = xcol.red / 256;
- col.g = xcol.green / 256;
- col.b = xcol.blue / 256;
-
// Create a valid X11 name of the form "#rrggbb" and change the
// LColor X11name to this. Don't want to trigger a redraw,
// as we're just changing the name not the RGB values.
fl_set_slider_value(dialog_->slider_value, hsv.v);
col = HSVColor(hsv.h, 1.0, 1.0);
- col.r = max(col.r, 0);
+ col.r = max(col.r, 0u);
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
fl_redraw_object(dialog_->dial_hue);
fl_unfreeze_form(dialog_->form);
}
-string const FormPreferences::Colors::X11hexname(RGBColor const & col) const
-{
- ostringstream ostr;
-
- ostr << '#' << std::setbase(16) << setfill('0')
- << setw(2) << col.r
- << setw(2) << col.g
- << setw(2) << col.b;
-
- return STRCONV(ostr.str());
-}
-
FormPreferences::Converters::Converters(FormPreferences & p)
: parent_(p)
void Modify();
///
void SwitchColorSpace() const;
- ///
- string const X11hexname(RGBColor const &) const;
///
FormPreferences & parent_;
string const lyx_gui::hexname(LColor::color col)
{
- 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) {
- lyxerr << "X can't find color \""
- << lcolor.getLyXName(col)
- << '"' << endl;
- return string();
- }
+ unsigned int r, g, b;
+ bool const success = getRGBColor(col, r, g, b);
+ if (!success) {
+ lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
+ << '"' << endl;
+ return string();
+ }
- ostringstream os;
+ ostringstream os;
- // Note that X stores the RGB values in the range 0 - 65535
- // whilst we require them in the range 0 - 255.
os << setbase(16) << setfill('0')
- << setw(2) << (xcol.red / 256)
- << setw(2) << (xcol.green / 256)
- << setw(2) << (xcol.blue / 256);
+ << setw(2) << r
+ << setw(2) << g
+ << setw(2) << b;
return STRCONV(os.str());
}
#include "xformsImage.h"
#include "graphics/GraphicsParams.h"
-#include "LColor.h"
+#include "Color.h"
#include "converter.h" // formats
#include "debug.h"
#include "support/LAssert.h"
}
-unsigned int packedcolor(LColor::color c)
+unsigned int packedcolor(LColor::color col)
{
- string const x11color = lcolor.getX11Name(c);
-
- Display * display = fl_get_display();
- Colormap cmap = fl_state[fl_get_vclass()].colormap;
- XColor xcol;
- XColor ccol;
- if (XLookupColor(display, cmap, x11color.c_str(), &xcol, &ccol) == 0)
- // Unable to parse x11color.
+ unsigned int r, g, b;
+ bool const success = getRGBColor(col, r, g, b);
+ if (!success)
+ // Set to black on failure
return FL_PACK(255,255,255);
- // Note that X stores the RGB values in the range 0 - 65535
- // whilst we require them in the range 0 - 255.
- unsigned int const r = xcol.red / 256;
- unsigned int const g = xcol.green / 256;
- unsigned int const b = xcol.blue / 256;
-
return FL_PACK(r, g, b);
}
}
+// A wrapper for the xforms routine, but this one accepts uint args
+unsigned long fl_getmcolor(int i,
+ unsigned int * r, unsigned int * g, unsigned int * b)
+{
+ int r2, g2, b2;
+ unsigned long ret_val = ::fl_getmcolor(i, &r2, &g2, &b2);
+ *r = r2;
+ *g = g2;
+ *b = b2;
+ return ret_val;
+}
+
+
// Set an FL_OBJECT to activated or deactivated
void setEnabled(FL_OBJECT * ob, bool enable)
{
class LyXLength;
+// A wrapper for the xforms routine, but this one accepts uint args
+unsigned long fl_getmcolor(int i, unsigned int * r, unsigned int * g,
+ unsigned int * b);
+
// what we always need for lengths
string const choice_Length_All =
"cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";