]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/ColorHandler.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / ColorHandler.C
index e6092483cc21a2c71f01edbb66eac8f409f1cedc..7b51fcbb1e8424adcfec89ba02875be9b2c69816 100644 (file)
@@ -1,11 +1,12 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file ColorHandler.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
- *     
- *         Copyright 1998-2001 The LyX Team
+ * \author unknown
  *
- *======================================================*/
+ * Full author contact details are available in file CREDITS
+ */
 
 #include <config.h>
 
 #include "gettext.h"
 #include "debug.h"
 
-#include <cmath>
-
 #include <boost/scoped_array.hpp>
+#include "BoostFormat.h"
+
+#include <cmath>
 
 #ifndef CXX_GLOBAL_CSTD
 using std::pow;
@@ -36,7 +38,7 @@ LyXColorHandler::LyXColorHandler()
        drawable = XCreatePixmap(display,
                                 RootWindow(display, fl_screen),
                                 10, 10, fl_get_visual_depth());
-       
+
        colormap = fl_state[fl_get_vclass()].colormap;
        // Clear the GC cache
        for (int i = 0; i <= LColor::ignore; ++i) {
@@ -73,10 +75,6 @@ unsigned long LyXColorHandler::colorPixel(LColor::color c)
 // Uses caching
 GC LyXColorHandler::getGCForeground(LColor::color c)
 {
-       //if (lyxerr.debugging()) {
-       //      lyxerr << "Painter drawable: " << drawable() << endl;
-       //}
-
        if (colorGCcache[c] != 0)
                return colorGCcache[c];
 
@@ -88,24 +86,50 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
        // Look up the RGB values for the color, and an approximate
        // color that we can hope to get on this display.
        if (XLookupColor(display, colormap, s.c_str(), &xcol, &ccol) == 0) {
-               lyxerr << _("LyX: Unknown X11 color ") << s
-                      << _(" for ") << lcolor.getGUIName(c) << '\n'
-                      << _("     Using black instead, sorry!") << endl;
+#if USE_BOOST_FORMAT
+               lyxerr << boost::format(
+                       _("LyX: Unknown X11 color %1$s for %2$s\n"
+                         "     Using black instead, sorry!"))
+                       % s
+                       % lcolor.getGUIName(c)
+                      << endl;
+#else
+               lyxerr << _("LyX: Unknown X11 color ") << s << _(" for ")
+                      << lcolor.getGUIName(c)
+                      << _("\n     Using black instead, sorry!") << endl;
+#endif
                unsigned long bla = BlackPixel(display,
                                               DefaultScreen(display));
                val.foreground = bla;
        // Try the exact RGB values first, then the approximate.
        } else if (XAllocColor(display, colormap, &xcol) != 0) {
                if (lyxerr.debugging(Debug::GUI)) {
+#if USE_BOOST_FORMAT
+                       lyxerr << boost::format(
+                               _("LyX: X11 color %1$s allocated for %2$s"))
+                               % s
+                               % lcolor.getGUIName(c)
+                              << endl;
+#else
                        lyxerr << _("LyX: X11 color ") << s
-                              << _(" allocated for ")
-                              << lcolor.getGUIName(c) << endl;
+                              << _(" allocated for ") << lcolor.getGUIName(c)
+                              << endl;
+#endif
                }
                val.foreground = xcol.pixel;
        } else if (XAllocColor(display, colormap, &ccol)) {
+#if USE_BOOST_FORMAT
+               lyxerr << boost::format(
+                       _("LyX: Using approximated X11 color %1$s"
+                         " allocated for %2$s"))
+                       % s
+                       % lcolor.getGUIName(c)
+                      << endl;
+#else
                lyxerr << _("LyX: Using approximated X11 color ") << s
-                      << _(" allocated for ")
-                      << lcolor.getGUIName(c) << endl;
+                      << _(" allocated for ") << lcolor.getGUIName(c)
+                      << endl;
+#endif
                val.foreground = xcol.pixel;
        } else {
                // Here we are traversing the current colormap to find
@@ -144,30 +168,48 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
                                closest_pixel = t;
                        }
                }
+
+#if USE_BOOST_FORMAT
+               lyxerr << boost::format(
+                       _("LyX: Couldn't allocate '%1$s' for %2$s"
+                         " with (r,g,b)=(%3$d,%4$d,%5$d).\n"
+                         "     Using closest allocated color"
+                         " with (r,g,b)=(%6$d,%7$d,%8$d) instead.\n"
+                         "Pixel [%9$d] is used."))
+                       % s
+                       % lcolor.getGUIName(c)
+                       % xcol.red % xcol.green % xcol.blue
+                       % cmap[closest_pixel].red
+                       % cmap[closest_pixel].green
+                       % cmap[closest_pixel].blue
+                       % closest_pixel
+                      << endl;
+#else
                lyxerr << _("LyX: Couldn't allocate '") << s
                       << _("' for ") << lcolor.getGUIName(c)
                       << _(" with (r,g,b)=(")
-                      << xcol.red << "," << xcol.green << ","
-                      << xcol.blue << ").\n"
-                      << _("     Using closest allocated "
-                           "color with (r,g,b)=(")
+                      << xcol.red << "," << xcol.green << "," << xcol.blue
+                      << _(").\n")
+                      << _("     Using closest allocated color with (r,g,b)=(")
                       << cmap[closest_pixel].red << ","
                       << cmap[closest_pixel].green << ","
-                      << cmap[closest_pixel].blue << _(") instead.\n")
-                      << _("Pixel [") << closest_pixel << _("] is used.")
+                      << cmap[closest_pixel].blue
+                      << _(") instead.\nPixel [")
+                      << closest_pixel << _("] is used.")
                       << endl;
+#endif
                val.foreground = cmap[closest_pixel].pixel;
        }
 
        val.function = GXcopy;
        return colorGCcache[c] = XCreateGC(display, drawable,
-                                   GCForeground | GCFunction, &val);
+                                          GCForeground | GCFunction, &val);
 }
 
 
 // Gets GC for line
-GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls,
-                                 PainterBase::line_width lw, LColor::color c)
+GC LyXColorHandler::getGCLinepars(Painter::line_style ls,
+                                 Painter::line_width lw, LColor::color c)
 {
        //if (lyxerr.debugging()) {
        //      lyxerr << "Painter drawable: " << drawable() << endl;
@@ -183,24 +225,21 @@ GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls,
        XGetGCValues(display, getGCForeground(c), GCForeground, &val);
 
        switch (lw) {
-       case PainterBase::line_thin:
+       case Painter::line_thin:
                val.line_width = 0;
                break;
-       case PainterBase::line_thick:
+       case Painter::line_thick:
                val.line_width = 2;
                break;
        }
 
        switch (ls) {
-       case PainterBase::line_solid:
+       case Painter::line_solid:
                val.line_style = LineSolid;
                break;
-       case PainterBase::line_onoffdash:
+       case Painter::line_onoffdash:
                val.line_style = LineOnOffDash;
                break;
-       case PainterBase::line_doubledash:
-               val.line_style = LineDoubleDash;
-               break;
        }
 
 
@@ -236,12 +275,12 @@ void LyXColorHandler::updateColor (LColor::color c)
                                gc = it->second;
                                XFreeGC(display, gc);
                                lineGCcache.erase(it);
-                               getGCLinepars(PainterBase::line_style(ls),
-                                             PainterBase::line_width(lw), c);
+                               getGCLinepars(Painter::line_style(ls),
+                                             Painter::line_width(lw), c);
                        }
                }
-
 }
 
+
 //
 boost::scoped_ptr<LyXColorHandler> lyxColorHandler;