]> git.lyx.org Git - lyx.git/blobdiff - src/ColorHandler.C
- remove some unused code
[lyx.git] / src / ColorHandler.C
index 5b2571fbdd1b6f6ace0565a06c429dc5ba5c2c63..fcd516610e6a08cdbcf71a431bf3b457d75d6a8d 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
  *
  *======================================================*/
 
 
 #include <cmath>
 
-#include FORMS_H_LOCATION
-#include "debug.h"
-
+#include "frontends/GUIRunTime.h"
 #include "ColorHandler.h"
+#include "LColor.h"
 #include "gettext.h"
+#include "debug.h"
 
 using std::endl;
 
 LyXColorHandler::LyXColorHandler() 
 {
-       display = fl_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;
@@ -49,7 +50,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);
        }
 }
 
@@ -105,7 +106,7 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
 
                XColor * cmap = new XColor[vi->map_entries];
 
-               for(int i = 0; i < vi->map_entries; ++i) {
+               for (int i = 0; i < vi->map_entries; ++i) {
                        cmap[i].pixel = i;
                }
                XQueryColors(display, colormap, cmap, vi->map_entries);
@@ -114,7 +115,7 @@ GC LyXColorHandler::getGCForeground(LColor::color c)
                int closest_pixel = 0;
                double closest_distance = 1e20; // we want to minimize this
                double distance = 0;
-               for(int t = 0; t < vi->map_entries; ++t) {
+               for (int t = 0; t < vi->map_entries; ++t) {
                        // The Euclidean distance between two points in 
                        // a three-dimensional space, the RGB color-cube,
                        // is used as the distance measurement between two
@@ -195,5 +196,34 @@ GC LyXColorHandler::getGCLinepars(PainterBase::line_style ls,
                          GCCapStyle | GCJoinStyle | GCFunction, &val);
 }
 
+
+// update GC cache after color redefinition
+void LyXColorHandler::updateColor (LColor::color c)
+{
+       // color GC cache
+       GC gc = colorGCcache[c];
+       if (gc != NULL) {
+               XFreeGC(display, gc);
+               colorGCcache[c] = NULL;
+               getGCForeground(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);
+                               getGCLinepars(PainterBase::line_style(ls),
+                                               PainterBase::line_width(lw), c);
+                       }
+               }
+}
+
 //
-LyXColorHandler * lyxColorHandler;
+boost::scoped_ptr<LyXColorHandler> lyxColorHandler;