]> git.lyx.org Git - lyx.git/blobdiff - src/ColorHandler.C
Some more fixes to compiler warnings.
[lyx.git] / src / ColorHandler.C
index 43ec7f4606d403c71b866520133f08cbd3c9aa69..416f09fea706e055c519c15c4c972f29d4faa818 100644 (file)
@@ -1,10 +1,9 @@
-// -*- C++ -*-
 /* This file is part of
  * ======================================================
  * 
  *           LyX, The Document Processor
  *      
- *         Copyright 1998-2000 The LyX Team
+ *         Copyright 1998-2001 The LyX Team
  *
  *======================================================*/
 
 #pragma implementation
 #endif
 
-#include <cmath>
-
-#include FORMS_H_LOCATION
-#include "debug.h"
-
 #include "ColorHandler.h"
 #include "LColor.h"
 #include "gettext.h"
+#include "debug.h"
+
+#include "frontends/GUIRunTime.h"
+
+#include <cmath>
 
 using std::endl;
 
+
 LyXColorHandler::LyXColorHandler() 
 {
-       display = fl_get_display();
-       drawable = XCreatePixmap(display, fl_root, 10, 10,
-                                fl_get_visual_depth());
+       display = GUIRunTime::x11Display();
+       drawable = XCreatePixmap(display,
+                                RootWindow(display, GUIRunTime::x11Screen()),
+                                10, 10,
+                                GUIRunTime::x11VisualDepth());
        
-       colormap = fl_state[fl_get_vclass()].colormap;
+       colormap = GUIRunTime::x11Colormap();
        // Clear the GC cache
        for (int i = 0; i <= LColor::ignore; ++i) {
                colorGCcache[i] = 0;
@@ -50,7 +52,7 @@ LyXColorHandler::~LyXColorHandler()
        // Iterate over the line cache and Free the GCs
        for (LineGCCache::iterator lit = lineGCcache.begin();
             lit != lineGCcache.end(); ++lit) {
-               XFreeGC(display, (*lit).second);
+               XFreeGC(display, lit->second);
        }
 }
 
@@ -71,10 +73,12 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
        //      lyxerr << "Painter drawable: " << drawable() << endl;
        //}
        
-       if (colorGCcache[c] != 0) return colorGCcache[c];
+       if (colorGCcache[c] != 0)
+               return colorGCcache[c];
 
-       XColor xcol, ccol;
-       string s = lcolor.getX11Name(c);
+       XColor xcol;
+       XColor ccol;
+       string const s = lcolor.getX11Name(c);
        XGCValues val;
 
        // Look up the RGB values for the color, and an approximate
@@ -82,13 +86,13 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
         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;
+                      << _("     Using black instead, sorry!") << endl;
                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()) {
+               if (lyxerr.debugging(Debug::GUI)) {
                        lyxerr << _("LyX: X11 color ") << s
                               << _(" allocated for ") 
                               << lcolor.getGUIName(c) << endl;
@@ -104,12 +108,12 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
                // the color closest to the one we want.
                Visual * vi = DefaultVisual(display, DefaultScreen(display));
 
-               XColor * cmap = new XColor[vi->map_entries];
+               boost::scoped_array<XColor> cmap(new XColor[vi->map_entries]);
 
                for (int i = 0; i < vi->map_entries; ++i) {
                        cmap[i].pixel = i;
                }
-               XQueryColors(display, colormap, cmap, vi->map_entries);
+               XQueryColors(display, colormap, cmap.get(), vi->map_entries);
 
                // Walk through the cmap and look for close colors.
                int closest_pixel = 0;
@@ -149,7 +153,6 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
                       << _("Pixel [") << closest_pixel << _("] is used.") 
                       << endl;
                val.foreground = cmap[closest_pixel].pixel;
-               delete[] cmap;
        }
 
        val.function = GXcopy;
@@ -160,29 +163,40 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
 
 // Gets GC for line
 GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls,
-                         PainterBase::line_width lw, LColor::color c)
+                                 PainterBase::line_width lw, LColor::color c)
 {
        //if (lyxerr.debugging()) {
        //      lyxerr << "Painter drawable: " << drawable() << endl;
        //}
        
-       int index = lw + (ls << 1) + (c << 3);
+       int index = lw + (ls << 1) + (c << 6);
 
-       if (lineGCcache.find(index) != lineGCcache.end())
-               return lineGCcache[index];
+       LineGCCache::iterator it = lineGCcache.find(index);
+       if (it != lineGCcache.end())
+               return it->second;
 
        XGCValues val;
        XGetGCValues(display, getGCForeground(c), GCForeground, &val);
        
        switch (lw) {
-       case PainterBase::line_thin:    val.line_width = 0; break;
-       case PainterBase::line_thick:   val.line_width = 2; break;
+       case PainterBase::line_thin:
+               val.line_width = 0;
+               break;
+       case PainterBase::line_thick:
+               val.line_width = 2;
+               break;
        }
        
        switch (ls) {
-       case PainterBase::line_solid:   val.line_style = LineSolid; break;
-       case PainterBase::line_onoffdash:       val.line_style = LineOnOffDash; break;
-       case PainterBase::line_doubledash:      val.line_style = LineDoubleDash; break;
+       case PainterBase::line_solid:
+               val.line_style = LineSolid;
+               break;
+       case PainterBase::line_onoffdash:
+               val.line_style = LineOnOffDash;
+               break;
+       case PainterBase::line_doubledash:
+               val.line_style = LineDoubleDash;
+               break;
        }
 
 
@@ -202,7 +216,7 @@ void LyXColorHandler::updateColor (LColor::color c)
 {
        // color GC cache
        GC gc = colorGCcache[c];
-       if (gc != NULL) {
+       if (gc != 0) {
                XFreeGC(display, gc);
                colorGCcache[c] = NULL;
                getGCForeground(c);
@@ -210,20 +224,20 @@ void LyXColorHandler::updateColor (LColor::color c)
 
        // line GC cache
 
-       int index, ls, lw;
-       for (ls=0; ls<3; ++ls)
-               for (lw=0; lw<2; ++lw) {
-                       index = lw + (ls << 1) + (c << 3);
-                       if (lineGCcache.find(index) != lineGCcache.end()) {
-                               gc = lineGCcache[index];
-                               XFreeGC(display,gc);
-                               lineGCcache.erase(index);
+       for (int ls = 0; ls < 3; ++ls)
+               for (int lw = 0; lw < 2; ++lw) {
+                       int const index = lw + (ls << 1) + (c << 6);
+                       LineGCCache::iterator it = lineGCcache.find(index);
+                       if (it != lineGCcache.end()) {
+                               gc = it->second;
+                               XFreeGC(display, gc);
+                               lineGCcache.erase(it);
                                getGCLinepars(PainterBase::line_style(ls),
-                                               PainterBase::line_width(lw), c);
+                                             PainterBase::line_width(lw), c);
                        }
                }
  
 }
 
 //
-LyXColorHandler * lyxColorHandler;
+boost::scoped_ptr<LyXColorHandler> lyxColorHandler;